I'm using SlickGrid with DataView and I'm trying to set a default sort column on my table. Is there a way to trigger the sort or set an option so the column is sorted on load?
I'm using SlickGrid with DataView and I'm trying to set a default sort column on my table. Is there a way to trigger the sort or set an option so the column is sorted on load?
Share Improve this question asked Mar 20, 2012 at 15:04 podcastfan88podcastfan88 1,0803 gold badges15 silver badges30 bronze badges4 Answers
Reset to default 10On the latest version you could do this:
grid.setSortColumn("myColId",true); //columnId, ascending
You can also set multiple with setSortColumn*s*
See my solution here. This applies sort on a column initially without using Dataview.
Calling sort on slickgrid
I think it does what you want.
Btw since you are using Dataview. You can also give this a try. But I have not personally tried this.
dataview.reSort()
I had an interesting thought which worked, and that was to just enable the multi-column header sorting (example-multi-column-sort.html), and then once the grid was loaded simulate a click() on the header row I wanted to be sorted when the grid first appeared ("time" is the name of my column I was sorting). The ID of the column headers is calculated similar to the id for the root div of the grid (at least for now :0) ):
var gridId = $('#myGrid').attr("class");
gridId = '#'+gridId.replace(" ui-widget","")+'time';
$(gridId).click();
The user then can click whatever other column headers they want, but I just clicked the first one for them.
This ended up being my solution just give slick grid the data in the way you want it sorted. then let multisort handle it the rest of the time. still doesn't sold programmatically setting the sort and having the grid update but its quick and easy
this.data = res.data.sort((a, b) => {
let x = a[config.sortField], y = b[config.sortField];
return (x == y ? 0 : (x > y ? 1 : -1));//no ===
})