Magento collection order by name - string value - magento

I have a grid in front end. and i need to put sort function for that grid column. I need to sort by billing name. I add bellow code into my collection;
if(!empty($data['sort_billto'])){
$collection->addAttributeToSort('billing_name', $data['sort_billto']);
}
From $data['sort_billto'] i am getting asc oe desc. That's fine, because this way works for int values. But not working for string, billing name.
Can anyone please help me.
Thank You

Usually your code should work, the problem may seem elsewhere. Give this a try
$collection->setOrder('billing_name', $data['sort_billto'])
If this doesnt work, debug your complete code.
HTH

Related

LOOKUP and REFERENCE Function - Cannot get either to work - merging tables

I have numerous tables that I want to combine into one single table and build my dashboard from there. I am trying to do this with LOOKUPVALUE because I cannot get the relationships working correctly, otherwise I would be trying RELATED().
I want to fill in the values of Data[NEW] by looking up Data[Issue Key] in Sprint Name[Issue Key] and returning the corresponding value of Sprint Name[Sprint Name]
So far, I have
LOOKUPVALUE('Sprint Name'[Issue Key],'Sprint Name'[Issue Key],Data[Issue Key])
With this, I am getting the Issue Key values in the New column, but I want the Sprint Name. I have tried different combinations but still cannot get it to work, I either get a blank column or an error message.
Any help would be much appreciated, thank you!
Try This:
Result =
LOOKUPVALUE (
'Sprint Name'[Sprint Name],
'Sprint Name'[Issue Key], Data[Issue Key]
)

column "likes.id" must appear in the GROUP BY clause or be used in an aggregate function

So I am trying to add top posts functionality for my Sinatra project using postgresql with the following statement Like.group(:exercise_id).order('COUNT(exercise_id) DESC').each do |like|
But when I try this I get an error saying column "likes.id" must appear in the GROUP BY clause or be used in an aggregate function
And when I add this
Like.group(:exercise_id, :id).order('COUNT(exercise_id) DESC')
It gives me the whole table when all I want is to group by likes. Is there a workaround for this?
What the error is telling you, is that you're selecting for "likes.id", but there is no single likes.id that the database can give you.
This is because by default when you don't tell Rails what you need, Rails will select EVERYTHING.
Think, do you actually need "likes.id"? Looks to me that you're grouping by exercise_id so what you're trying to get is exercises and their like counts. (correct me if I'm wrong.) You don't actually need specific like id-s.
If that's so, we need to tell rails about our intention.
Like.group(:exercise_id).order('COUNT(exercise_id) DESC').select(:exercise_id)
If you also need the count itself, just add it to the select.
Something else you might want to try is just .count. It's pretty smart and will respect your grouping. See if this helps.
Like.group(:exercise_id).count

Google Sheets - QUERY order by dependent drop down

I am trying to setup a QUERY with dynamic ordering. I've tried to link the ORDER BY function to the output of the dropdown menu but that doesnt seem to work. I have recreated the problem with a simple example: https://docs.google.com/spreadsheets/d/1m3Lhm5lp2DW7XF8hRbDAiOAAsOyCXrie-Nc-0bWG6hA/edit?usp=sharing
I've created a table (3x4) with three variable and would like to dynamically sort the table by each variable through QUERY both ascending and descending.
Would also be interested to learn if it's possible to dynamically setup the direction (ACS or DESC).
Any suggestions would be much appreciated.
Kind regards,
Webko
try:
=QUERY({A2:C6}, "order by Col"&MATCH(F1, A2:C2, 0)&" "&G1)
where G1 dropdown is asc,desc

jqgrid data is reordering automatically , in collapsegrid

when I am providing the dataobject to the jqgrid its getting reshuffled , not able to identify the cause, please see the working fiddlle fiddle jqgrid
the rows are not displaying in the order they are supplied, any help will be really appreciated.
Required out put is that all data should come in the order provided, please refer this fiddle
for more info.
I'm not sure that I correctly understand your requirements. I suppose that you should replace the options
"groupText":["getGrouptext"]
"datatype":"local"
"data":[...]
to
"groupText":["{0}"]
"datatype":"jsonstring"
"datastr":[...]
See http://jsfiddle.net/OlegKi/47g5pLv4/2/

Default sorting is not working

Please refer this following url http://www.trendycollections.in/kids-wear/boys-wear.html
All sorting is working Fine. But I have different issue. In the above url if i chose Price lowest under the sort by option then i will move to http://www.trendycollections.in/women-collections/sarees/designer-sarees.html, That category page also having Price lowest sorting.
If i chose price highest,Next category page also sorting by price highest
I think, i need to reset sort by option. I have set default sorting under system->config->catalog->front end->Product Listing Sort by as Best value. I can’t find where am i doing wrong here. if anybody know, please help me guys
The sort order parameter is stored in session.
You can switch it off by calling Mage_Catalog_Block_Product_List_Toolbar::disableParamsMemorizing method
OR
by setting params_memorize_allowed in catalog session. Mage::getSingleton('catalog/session')->setParamsMemorizeAllowed(true)

Resources