Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

w2ui grid how to get sortData to sort on initialize

Tags:

w2ui

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' }
    ]
});
});
like image 297
Maher Avatar asked Oct 14 '25 09:10

Maher


1 Answers

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');
}
like image 154
Delforge Avatar answered Oct 19 '25 01:10

Delforge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!