Sorting a custom column - Customer Grid The 2019 Stack Overflow Developer Survey Results Are InCannot sorting joined column in Magento GridHow do I make this custom expression column I have developed for the customer grid display sortable?Sorting and filtering not working with custom column in Customer Grid MagentoMagento 2 - How to add a custom column in customer gridSorting custom column rendererCustom Grid sorting functionhow can i add shipping carrier column in admin pageMagento 2 adminhtml custom column sorting ascending and descendingAdd column in Customer grid based on module's ModelMagento - Add customer attribute to order grid
Accepted by European university, rejected by all American ones I applied to? Possible reasons?
Is it okay to consider publishing in my first year of PhD?
Why was M87 targeted for the Event Horizon Telescope instead of Sagittarius A*?
What information about me do stores get via my credit card?
Ubuntu Server install with full GUI
How do you keep chess fun when your opponent constantly beats you?
Pokemon Turn Based battle (Python)
Will it cause any balance problems to have PCs level up and gain the benefits of a long rest mid-fight?
A female thief is not sold to make restitution -- so what happens instead?
Loose spokes after only a few rides
Deal with toxic manager when you can't quit
How come people say “Would of”?
Why couldn't they take pictures of a closer black hole?
What is the motivation for a law requiring 2 parties to consent for recording a conversation
Why don't hard Brexiteers insist on a hard border to prevent illegal immigration after Brexit?
How to support a colleague who finds meetings extremely tiring?
How to charge AirPods to keep battery healthy?
What does Linus Torvalds mean when he says that Git "never ever" tracks a file?
Why didn't the Event Horizon Telescope team mention Sagittarius A*?
Getting crown tickets for Statue of Liberty
What is this sharp, curved notch on my knife for?
How to obtain a position of last non-zero element
What is preventing me from simply constructing a hash that's lower than the current target?
Can an undergraduate be advised by a professor who is very far away?
Sorting a custom column - Customer Grid
The 2019 Stack Overflow Developer Survey Results Are InCannot sorting joined column in Magento GridHow do I make this custom expression column I have developed for the customer grid display sortable?Sorting and filtering not working with custom column in Customer Grid MagentoMagento 2 - How to add a custom column in customer gridSorting custom column rendererCustom Grid sorting functionhow can i add shipping carrier column in admin pageMagento 2 adminhtml custom column sorting ascending and descendingAdd column in Customer grid based on module's ModelMagento - Add customer attribute to order grid
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have added in order count and last order date to the customer grid which is working fine, however it is not sortable or filterable in the grid.
I have done some searching but can't seem to find a solution that makes any sense, can someone explain how I can achieve this?
protected function _prepareCollection()
$collection = Mage::getResourceModel('customer/customer_collection')
->addNameToSelect()
->addAttributeToSelect('email')
->addAttributeToSelect('created_at')
->addAttributeToSelect('group_id')
->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left')
->joinAttribute('billing_company', 'customer_address/company', 'default_billing', null, 'left');
$sql = 'SELECT COUNT(*) FROM sales_flat_order AS o WHERE o.customer_id=e.entity_id';
$expr = new Zend_Db_Expr('(' . $sql . ')');
$collection->getSelect()->from(null, array('orders_count'=>$expr));
$sql ='SELECT MAX(o.created_at) FROM sales_flat_order AS o WHERE o.customer_id = e.entity_id ';
$expr = new Zend_Db_Expr('(' . $sql . ')');
$collection->getSelect()->from(null, array('last_order_date'=>$expr));
$this->setCollection($collection);
return parent::_prepareCollection();
//Rest of code omitted for brevity
protected function _prepareColumns()
//code omitted for brevity
$this->addColumn('orders_count', array(
'header' => Mage::helper('customer')->__('Total Orders'),
'align' => 'left',
'width' => '40px',
'index' => 'orders_count',
'type' => 'number',
));
$this->addColumn('last_order_date', array(
'header' => Mage::helper('customer')->__('Last Order Date'),
'type' => 'datetime',
'align' => 'center',
'index' => 'last_order_date',
'gmtoffset' => true,
));
//additional code omitted
magento-1.9 sorting column customer-grid
add a comment |
I have added in order count and last order date to the customer grid which is working fine, however it is not sortable or filterable in the grid.
I have done some searching but can't seem to find a solution that makes any sense, can someone explain how I can achieve this?
protected function _prepareCollection()
$collection = Mage::getResourceModel('customer/customer_collection')
->addNameToSelect()
->addAttributeToSelect('email')
->addAttributeToSelect('created_at')
->addAttributeToSelect('group_id')
->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left')
->joinAttribute('billing_company', 'customer_address/company', 'default_billing', null, 'left');
$sql = 'SELECT COUNT(*) FROM sales_flat_order AS o WHERE o.customer_id=e.entity_id';
$expr = new Zend_Db_Expr('(' . $sql . ')');
$collection->getSelect()->from(null, array('orders_count'=>$expr));
$sql ='SELECT MAX(o.created_at) FROM sales_flat_order AS o WHERE o.customer_id = e.entity_id ';
$expr = new Zend_Db_Expr('(' . $sql . ')');
$collection->getSelect()->from(null, array('last_order_date'=>$expr));
$this->setCollection($collection);
return parent::_prepareCollection();
//Rest of code omitted for brevity
protected function _prepareColumns()
//code omitted for brevity
$this->addColumn('orders_count', array(
'header' => Mage::helper('customer')->__('Total Orders'),
'align' => 'left',
'width' => '40px',
'index' => 'orders_count',
'type' => 'number',
));
$this->addColumn('last_order_date', array(
'header' => Mage::helper('customer')->__('Last Order Date'),
'type' => 'datetime',
'align' => 'center',
'index' => 'last_order_date',
'gmtoffset' => true,
));
//additional code omitted
magento-1.9 sorting column customer-grid
Would you mind adding some context to your second code example? I'm assuming it's a snippet from the grid class'_prepareColumns()
method, but it would be nice to have some clarity there for others.
– tjons
Dec 13 '16 at 14:03
@tjons sorry about that! Updated :)
– KiwisTasteGood
Dec 13 '16 at 14:07
No problem! Thanks for doing that. I just posted an answer, please let me know if it helps...
– tjons
Dec 13 '16 at 14:10
add a comment |
I have added in order count and last order date to the customer grid which is working fine, however it is not sortable or filterable in the grid.
I have done some searching but can't seem to find a solution that makes any sense, can someone explain how I can achieve this?
protected function _prepareCollection()
$collection = Mage::getResourceModel('customer/customer_collection')
->addNameToSelect()
->addAttributeToSelect('email')
->addAttributeToSelect('created_at')
->addAttributeToSelect('group_id')
->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left')
->joinAttribute('billing_company', 'customer_address/company', 'default_billing', null, 'left');
$sql = 'SELECT COUNT(*) FROM sales_flat_order AS o WHERE o.customer_id=e.entity_id';
$expr = new Zend_Db_Expr('(' . $sql . ')');
$collection->getSelect()->from(null, array('orders_count'=>$expr));
$sql ='SELECT MAX(o.created_at) FROM sales_flat_order AS o WHERE o.customer_id = e.entity_id ';
$expr = new Zend_Db_Expr('(' . $sql . ')');
$collection->getSelect()->from(null, array('last_order_date'=>$expr));
$this->setCollection($collection);
return parent::_prepareCollection();
//Rest of code omitted for brevity
protected function _prepareColumns()
//code omitted for brevity
$this->addColumn('orders_count', array(
'header' => Mage::helper('customer')->__('Total Orders'),
'align' => 'left',
'width' => '40px',
'index' => 'orders_count',
'type' => 'number',
));
$this->addColumn('last_order_date', array(
'header' => Mage::helper('customer')->__('Last Order Date'),
'type' => 'datetime',
'align' => 'center',
'index' => 'last_order_date',
'gmtoffset' => true,
));
//additional code omitted
magento-1.9 sorting column customer-grid
I have added in order count and last order date to the customer grid which is working fine, however it is not sortable or filterable in the grid.
I have done some searching but can't seem to find a solution that makes any sense, can someone explain how I can achieve this?
protected function _prepareCollection()
$collection = Mage::getResourceModel('customer/customer_collection')
->addNameToSelect()
->addAttributeToSelect('email')
->addAttributeToSelect('created_at')
->addAttributeToSelect('group_id')
->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left')
->joinAttribute('billing_company', 'customer_address/company', 'default_billing', null, 'left');
$sql = 'SELECT COUNT(*) FROM sales_flat_order AS o WHERE o.customer_id=e.entity_id';
$expr = new Zend_Db_Expr('(' . $sql . ')');
$collection->getSelect()->from(null, array('orders_count'=>$expr));
$sql ='SELECT MAX(o.created_at) FROM sales_flat_order AS o WHERE o.customer_id = e.entity_id ';
$expr = new Zend_Db_Expr('(' . $sql . ')');
$collection->getSelect()->from(null, array('last_order_date'=>$expr));
$this->setCollection($collection);
return parent::_prepareCollection();
//Rest of code omitted for brevity
protected function _prepareColumns()
//code omitted for brevity
$this->addColumn('orders_count', array(
'header' => Mage::helper('customer')->__('Total Orders'),
'align' => 'left',
'width' => '40px',
'index' => 'orders_count',
'type' => 'number',
));
$this->addColumn('last_order_date', array(
'header' => Mage::helper('customer')->__('Last Order Date'),
'type' => 'datetime',
'align' => 'center',
'index' => 'last_order_date',
'gmtoffset' => true,
));
//additional code omitted
magento-1.9 sorting column customer-grid
magento-1.9 sorting column customer-grid
edited Dec 13 '16 at 14:16
KiwisTasteGood
asked Dec 13 '16 at 12:38
KiwisTasteGoodKiwisTasteGood
482429
482429
Would you mind adding some context to your second code example? I'm assuming it's a snippet from the grid class'_prepareColumns()
method, but it would be nice to have some clarity there for others.
– tjons
Dec 13 '16 at 14:03
@tjons sorry about that! Updated :)
– KiwisTasteGood
Dec 13 '16 at 14:07
No problem! Thanks for doing that. I just posted an answer, please let me know if it helps...
– tjons
Dec 13 '16 at 14:10
add a comment |
Would you mind adding some context to your second code example? I'm assuming it's a snippet from the grid class'_prepareColumns()
method, but it would be nice to have some clarity there for others.
– tjons
Dec 13 '16 at 14:03
@tjons sorry about that! Updated :)
– KiwisTasteGood
Dec 13 '16 at 14:07
No problem! Thanks for doing that. I just posted an answer, please let me know if it helps...
– tjons
Dec 13 '16 at 14:10
Would you mind adding some context to your second code example? I'm assuming it's a snippet from the grid class'
_prepareColumns()
method, but it would be nice to have some clarity there for others.– tjons
Dec 13 '16 at 14:03
Would you mind adding some context to your second code example? I'm assuming it's a snippet from the grid class'
_prepareColumns()
method, but it would be nice to have some clarity there for others.– tjons
Dec 13 '16 at 14:03
@tjons sorry about that! Updated :)
– KiwisTasteGood
Dec 13 '16 at 14:07
@tjons sorry about that! Updated :)
– KiwisTasteGood
Dec 13 '16 at 14:07
No problem! Thanks for doing that. I just posted an answer, please let me know if it helps...
– tjons
Dec 13 '16 at 14:10
No problem! Thanks for doing that. I just posted an answer, please let me know if it helps...
– tjons
Dec 13 '16 at 14:10
add a comment |
2 Answers
2
active
oldest
votes
Columns in Magento are filterable and sortable by default when they correspond to a column in the database, but because you are creating a column that doesn't directly correspond to a table in the database, you have to specify which data to filter and sort on.
To add the column into the filtering process, use the filter_condition_callback
element in the column definition array. Specify it as a callable: array($this, 'functionName')
, where functionName
is replaced by a custom function you write to perform the filtering on the column. To specify the sort, specify the sort_index
element, defining it as the column to sort on.
Thanks! If I add'filter' => 'adminhtml/filter_type_class'
I get a blank white screen, adding'sortable' => true,
does nothing when I click to order the column they are all still in the wrong order
– KiwisTasteGood
Dec 13 '16 at 14:13
Well, you have to replaceadminhtml/filter_type_class
with the proper filter class name.
– tjons
Dec 13 '16 at 14:15
For the sort, there are two sort types: ascending and descending. I think descending is the default, but you may be looking for ascending. Click the top again.
– tjons
Dec 13 '16 at 14:24
@KiwisTasteGood Let me know if that works...
– tjons
Dec 13 '16 at 14:24
Thanks, can you point me in the direction of how I can create / find the filter_type_class I need? As for sorting I have tried ascending and descending with no luck see screenshot: pasteboard.co/9kM9JNzXq.png
– KiwisTasteGood
Dec 13 '16 at 14:26
|
show 1 more comment
My solution
need override method - _setCollectionOrder
will like
protected function _setCollectionOrder($column)
if (!$dir = $column->getDir())
return $this;
if($column->getIndex()=='orders_count')
mage::log($column->getIndex());
$collection = $this->getCollection();
$collection->getSelect()
->order("orders_count " . strtoupper($column->getDir()));
return $this;
if($column->getIndex()=='orders_total')
mage::log($column->getIndex());
$collection = $this->getCollection();
$collection->getSelect()
->order("orders_total " . strtoupper($column->getDir()));
return $this;
return parent::_setCollectionOrder($column);
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f150066%2fsorting-a-custom-column-customer-grid%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Columns in Magento are filterable and sortable by default when they correspond to a column in the database, but because you are creating a column that doesn't directly correspond to a table in the database, you have to specify which data to filter and sort on.
To add the column into the filtering process, use the filter_condition_callback
element in the column definition array. Specify it as a callable: array($this, 'functionName')
, where functionName
is replaced by a custom function you write to perform the filtering on the column. To specify the sort, specify the sort_index
element, defining it as the column to sort on.
Thanks! If I add'filter' => 'adminhtml/filter_type_class'
I get a blank white screen, adding'sortable' => true,
does nothing when I click to order the column they are all still in the wrong order
– KiwisTasteGood
Dec 13 '16 at 14:13
Well, you have to replaceadminhtml/filter_type_class
with the proper filter class name.
– tjons
Dec 13 '16 at 14:15
For the sort, there are two sort types: ascending and descending. I think descending is the default, but you may be looking for ascending. Click the top again.
– tjons
Dec 13 '16 at 14:24
@KiwisTasteGood Let me know if that works...
– tjons
Dec 13 '16 at 14:24
Thanks, can you point me in the direction of how I can create / find the filter_type_class I need? As for sorting I have tried ascending and descending with no luck see screenshot: pasteboard.co/9kM9JNzXq.png
– KiwisTasteGood
Dec 13 '16 at 14:26
|
show 1 more comment
Columns in Magento are filterable and sortable by default when they correspond to a column in the database, but because you are creating a column that doesn't directly correspond to a table in the database, you have to specify which data to filter and sort on.
To add the column into the filtering process, use the filter_condition_callback
element in the column definition array. Specify it as a callable: array($this, 'functionName')
, where functionName
is replaced by a custom function you write to perform the filtering on the column. To specify the sort, specify the sort_index
element, defining it as the column to sort on.
Thanks! If I add'filter' => 'adminhtml/filter_type_class'
I get a blank white screen, adding'sortable' => true,
does nothing when I click to order the column they are all still in the wrong order
– KiwisTasteGood
Dec 13 '16 at 14:13
Well, you have to replaceadminhtml/filter_type_class
with the proper filter class name.
– tjons
Dec 13 '16 at 14:15
For the sort, there are two sort types: ascending and descending. I think descending is the default, but you may be looking for ascending. Click the top again.
– tjons
Dec 13 '16 at 14:24
@KiwisTasteGood Let me know if that works...
– tjons
Dec 13 '16 at 14:24
Thanks, can you point me in the direction of how I can create / find the filter_type_class I need? As for sorting I have tried ascending and descending with no luck see screenshot: pasteboard.co/9kM9JNzXq.png
– KiwisTasteGood
Dec 13 '16 at 14:26
|
show 1 more comment
Columns in Magento are filterable and sortable by default when they correspond to a column in the database, but because you are creating a column that doesn't directly correspond to a table in the database, you have to specify which data to filter and sort on.
To add the column into the filtering process, use the filter_condition_callback
element in the column definition array. Specify it as a callable: array($this, 'functionName')
, where functionName
is replaced by a custom function you write to perform the filtering on the column. To specify the sort, specify the sort_index
element, defining it as the column to sort on.
Columns in Magento are filterable and sortable by default when they correspond to a column in the database, but because you are creating a column that doesn't directly correspond to a table in the database, you have to specify which data to filter and sort on.
To add the column into the filtering process, use the filter_condition_callback
element in the column definition array. Specify it as a callable: array($this, 'functionName')
, where functionName
is replaced by a custom function you write to perform the filtering on the column. To specify the sort, specify the sort_index
element, defining it as the column to sort on.
edited Dec 13 '16 at 14:42
answered Dec 13 '16 at 14:09
tjonstjons
1,756717
1,756717
Thanks! If I add'filter' => 'adminhtml/filter_type_class'
I get a blank white screen, adding'sortable' => true,
does nothing when I click to order the column they are all still in the wrong order
– KiwisTasteGood
Dec 13 '16 at 14:13
Well, you have to replaceadminhtml/filter_type_class
with the proper filter class name.
– tjons
Dec 13 '16 at 14:15
For the sort, there are two sort types: ascending and descending. I think descending is the default, but you may be looking for ascending. Click the top again.
– tjons
Dec 13 '16 at 14:24
@KiwisTasteGood Let me know if that works...
– tjons
Dec 13 '16 at 14:24
Thanks, can you point me in the direction of how I can create / find the filter_type_class I need? As for sorting I have tried ascending and descending with no luck see screenshot: pasteboard.co/9kM9JNzXq.png
– KiwisTasteGood
Dec 13 '16 at 14:26
|
show 1 more comment
Thanks! If I add'filter' => 'adminhtml/filter_type_class'
I get a blank white screen, adding'sortable' => true,
does nothing when I click to order the column they are all still in the wrong order
– KiwisTasteGood
Dec 13 '16 at 14:13
Well, you have to replaceadminhtml/filter_type_class
with the proper filter class name.
– tjons
Dec 13 '16 at 14:15
For the sort, there are two sort types: ascending and descending. I think descending is the default, but you may be looking for ascending. Click the top again.
– tjons
Dec 13 '16 at 14:24
@KiwisTasteGood Let me know if that works...
– tjons
Dec 13 '16 at 14:24
Thanks, can you point me in the direction of how I can create / find the filter_type_class I need? As for sorting I have tried ascending and descending with no luck see screenshot: pasteboard.co/9kM9JNzXq.png
– KiwisTasteGood
Dec 13 '16 at 14:26
Thanks! If I add
'filter' => 'adminhtml/filter_type_class'
I get a blank white screen, adding 'sortable' => true,
does nothing when I click to order the column they are all still in the wrong order– KiwisTasteGood
Dec 13 '16 at 14:13
Thanks! If I add
'filter' => 'adminhtml/filter_type_class'
I get a blank white screen, adding 'sortable' => true,
does nothing when I click to order the column they are all still in the wrong order– KiwisTasteGood
Dec 13 '16 at 14:13
Well, you have to replace
adminhtml/filter_type_class
with the proper filter class name.– tjons
Dec 13 '16 at 14:15
Well, you have to replace
adminhtml/filter_type_class
with the proper filter class name.– tjons
Dec 13 '16 at 14:15
For the sort, there are two sort types: ascending and descending. I think descending is the default, but you may be looking for ascending. Click the top again.
– tjons
Dec 13 '16 at 14:24
For the sort, there are two sort types: ascending and descending. I think descending is the default, but you may be looking for ascending. Click the top again.
– tjons
Dec 13 '16 at 14:24
@KiwisTasteGood Let me know if that works...
– tjons
Dec 13 '16 at 14:24
@KiwisTasteGood Let me know if that works...
– tjons
Dec 13 '16 at 14:24
Thanks, can you point me in the direction of how I can create / find the filter_type_class I need? As for sorting I have tried ascending and descending with no luck see screenshot: pasteboard.co/9kM9JNzXq.png
– KiwisTasteGood
Dec 13 '16 at 14:26
Thanks, can you point me in the direction of how I can create / find the filter_type_class I need? As for sorting I have tried ascending and descending with no luck see screenshot: pasteboard.co/9kM9JNzXq.png
– KiwisTasteGood
Dec 13 '16 at 14:26
|
show 1 more comment
My solution
need override method - _setCollectionOrder
will like
protected function _setCollectionOrder($column)
if (!$dir = $column->getDir())
return $this;
if($column->getIndex()=='orders_count')
mage::log($column->getIndex());
$collection = $this->getCollection();
$collection->getSelect()
->order("orders_count " . strtoupper($column->getDir()));
return $this;
if($column->getIndex()=='orders_total')
mage::log($column->getIndex());
$collection = $this->getCollection();
$collection->getSelect()
->order("orders_total " . strtoupper($column->getDir()));
return $this;
return parent::_setCollectionOrder($column);
add a comment |
My solution
need override method - _setCollectionOrder
will like
protected function _setCollectionOrder($column)
if (!$dir = $column->getDir())
return $this;
if($column->getIndex()=='orders_count')
mage::log($column->getIndex());
$collection = $this->getCollection();
$collection->getSelect()
->order("orders_count " . strtoupper($column->getDir()));
return $this;
if($column->getIndex()=='orders_total')
mage::log($column->getIndex());
$collection = $this->getCollection();
$collection->getSelect()
->order("orders_total " . strtoupper($column->getDir()));
return $this;
return parent::_setCollectionOrder($column);
add a comment |
My solution
need override method - _setCollectionOrder
will like
protected function _setCollectionOrder($column)
if (!$dir = $column->getDir())
return $this;
if($column->getIndex()=='orders_count')
mage::log($column->getIndex());
$collection = $this->getCollection();
$collection->getSelect()
->order("orders_count " . strtoupper($column->getDir()));
return $this;
if($column->getIndex()=='orders_total')
mage::log($column->getIndex());
$collection = $this->getCollection();
$collection->getSelect()
->order("orders_total " . strtoupper($column->getDir()));
return $this;
return parent::_setCollectionOrder($column);
My solution
need override method - _setCollectionOrder
will like
protected function _setCollectionOrder($column)
if (!$dir = $column->getDir())
return $this;
if($column->getIndex()=='orders_count')
mage::log($column->getIndex());
$collection = $this->getCollection();
$collection->getSelect()
->order("orders_count " . strtoupper($column->getDir()));
return $this;
if($column->getIndex()=='orders_total')
mage::log($column->getIndex());
$collection = $this->getCollection();
$collection->getSelect()
->order("orders_total " . strtoupper($column->getDir()));
return $this;
return parent::_setCollectionOrder($column);
answered yesterday
AlexAlex
265210
265210
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f150066%2fsorting-a-custom-column-customer-grid%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Would you mind adding some context to your second code example? I'm assuming it's a snippet from the grid class'
_prepareColumns()
method, but it would be nice to have some clarity there for others.– tjons
Dec 13 '16 at 14:03
@tjons sorry about that! Updated :)
– KiwisTasteGood
Dec 13 '16 at 14:07
No problem! Thanks for doing that. I just posted an answer, please let me know if it helps...
– tjons
Dec 13 '16 at 14:10