This is a migrated thread and some comments may be shown as answers.

grid.sort does not remove previous sort icons

5 Answers 206 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Michiel
Top achievements
Rank 1
Michiel asked on 03 Dec 2012, 05:52 PM
I try to set the sorting of a grid dynamically in javascript. Although this works with the grid.sort function, it does not update the UI correctly.

Go for example to http://demos.telerik.com/aspnet-mvc/grid/sorting?theme=vista

and run 
$("#Grid").data("tGrid").sort("ShipCountry-asc")
You will see that it does a correct sorting by sending ShipCountry-asc, but still shows the column OrderId as one of the sort columns (icon is still present). Do see that OrderId is not in the sort parameter.

Bug? Is there a workaround or another way to do this?

I dont want to do multicolumn sorting; I just want to set a new sort column and clear the old one. Even using sort("") will still show the old sort state.

5 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 06 Dec 2012, 03:57 PM
Hi Michiel,

 
Basically updating the UI of the grid after programmatically updating the sorting currently is not supported and you should remove the sorting icons before applying such sort. Please check the example below:

$("#Grid thead a span.t-icon").remove();
$("#Grid").data("tGrid").sort("ShipCountry-asc");
Kind Regards,
Vladimir Iliev
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
0
Michiel
Top achievements
Rank 1
answered on 06 Dec 2012, 04:26 PM
Thanks for the reply. I did found that similar trick and just removed the sort icons using jquery. 

You say it is not supported; so it is a bug? You can set the sort order and the grid does pick the new sort order perfectly and highlights the columns, but it just did not clean up the old state. Should the call to the .sort() not first remove the existing sort UI before applying the new UI?
0
Michiel
Top achievements
Rank 1
answered on 10 Dec 2012, 12:40 PM
Unfortunately it does not work. 

Same url as above
http://demos.telerik.com/aspnet-mvc/grid/sorting?theme=vista

and executing your code:

$("#Grid thead a span.t-icon").remove();
$("#Grid").data("tGrid").sort("ShipCountry-asc");

Yes, it will remove the icons, but will do an ajax call and adds the icon again to the OrderId column. Which is not in the sort options anymore. Even refreshing it will not help. I tried removing it from the columns object but that also does not help.

Any clue?
0
Accepted
Vladimir Iliev
Telerik team
answered on 11 Dec 2012, 12:10 PM
Hi Michiel,

 

Apologise that I mislead you -  you should clear the previous sorting from the column object also - please check the example below for single-column sorting:

$("#Grid thead a span.t-icon").remove();
grid = $("#Grid").data("tGrid");
 
for (var column in grid.columns) {
   
  //remove the sorting on each column
  grid.columns[column].order = "";
}
 
grid.sort("ShipCountry-asc");

Also as I mention in my previous reply the Sort method does not support clearing the previous sort and If such is needed I would suggest upgrading to KendoUI Grid.


Kind Regards,
Vladimir Iliev
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
0
Michiel
Top achievements
Rank 1
answered on 12 Dec 2012, 09:58 AM
Yes, this does work now. Thanks.

I'm a bit confused by your answer however; you provide a fix/work around and at the same time say we need to upgrade because it is not supported.
Upgrading is certainly something we want to do, we love KendoUI! However we used Telerik MVC controls a lot so it is rather time consuming and risky to upgrade. I can't see any place where I can fill support requests against the MVC controls anymore, but it would be nice if this can get fixed in a next release for the MVC controls. I know you cant support them forever, but we need some time to switch to Kendo UI :-)
Tags
Grid
Asked by
Michiel
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Michiel
Top achievements
Rank 1
Share this question
or