Reputation: 501
I have copied the example on the grid sortData
http://w2ui.com/web/docs/w2grid.sortData and added sortable:true
to lname
, but the grid does not sort until I click the header. What am I doing wrong.
Here is the jsfiddle: http://jsfiddle.net/snwaw16v/
$(function () {
$('#grid').w2grid({
name : 'grid',
columns: [
{ field: 'recid', caption: 'ID', size: '50px' },
{ field: 'lname', caption: 'Last Name', size: '30%', sortable: true },
{ field: 'fname', caption: 'First Name', size: '30%' },
{ field: 'email', caption: 'Email', size: '40%' },
{ field: 'sdate', caption: 'End Date', size: '120px' }
],
records: [
{ recid: 1, fname: 'John', lname: 'doe', email: '[email protected]', sdate: '1/3/2012' },
{ recid: 2, fname: 'Stuart', lname: 'Motzart', email: '[email protected]', sdate: '2/4/2012' },
{ recid: 3, fname: 'Jin', lname: 'Franson', email: '[email protected]', sdate: '4/23/2012' },
{ recid: 4, fname: 'Susan', lname: 'Ottie', email: '[email protected]', sdate: '5/3/2012' },
{ recid: 5, fname: 'Kelly', lname: 'Silver', email: '[email protected]', sdate: '4/3/2012' },
{ recid: 6, fname: 'Francis', lname: 'Gatos', email: '[email protected]', sdate: '2/5/2012' }
],
sortData: [
{ field: 'lname', direction: 'asc' }
]
});
});
Upvotes: 4
Views: 2466
Reputation: 21
gridData = $('#grid').w2grid({
// Keep your existed code
});
// Add this line code
gridData.localSort();
Hope this help
Upvotes: 1
Reputation: 792
You can sort the grid on render using sort method with the onRender event.
You may add this to your grid object :
onRender: function(event){
this.sort('lname', 'asc');
}
Upvotes: 1