Closed avacondios closed 11 years ago
Please specify what version do you use. Using current master version https://github.com/vitmalina/w2ui/blob/master/dist/w2ui.js, it seems to work fine. As for the date you either need to use yyyy-mm-dd format of unix timestamp in records array for the field. You can render it differently with the render function, but the data needs to be in that format.
With yyyy/mm/dd, the date field is working. But for numbers, not . For example, 19 is greater than 1750.
Can you please send me your JSON file
Please check the following code including w2Grid initialization and data :+1:
$('#C9XTvNvQ').w2grid( {name: 'C9XTvNvQ_grid', header:'Header Title', show: {header : false,toolbar : true,columnHeaders : true,footer : false,lineNumbers : true,selectColumn : true,expandColumn : false,toolbarAdd : true,toolbarDelete : true,toolbarSave : true,toolbarSearch : true,toolbarColumns : true,toolbarReload : true}, columns: [ {field:'Amount',size:'200px',min:50,hidden:false,sortable:true,render:'float',searchable:'float',resizable:true,attr:'',editable:{type:'float'},caption:'The Amount'}, {field:'Author',size:'200px',min:50,hidden:false,sortable:true,render:'text',searchable:'text',resizable:true,attr:'',editable:{type:'text'},caption:'The Author'}, {field:'Country',size:'200px',min:50,hidden:false,sortable:true,render:'text',searchable:'text',resizable:true,attr:'',editable:{type:'text'},caption:'Country'}, {field:'Instock',size:'200px',min:50,hidden:false,sortable:true,render:'checkbox',searchable:'checkbox',resizable:true,attr:'',editable:{type:'checkbox'},caption:'Is in stock'}, {field:'ShippingDate',size:'200px',min:50,hidden:false,sortable:true,render: 'date',searchable:'date',resizable:true,attr:'',editable:{type:'date'},caption:'Shipping Date'} ], searches: [ {field:'Amount',type:'float',hidden:false,caption:'Amount'}, {field:'Author',type:'text',hidden:true,caption:'Author'}, {field:'Country',type:'text',hidden:false,caption:'Country'}, {field:'Instock',type:'',hidden:false,caption:'Instock'}, {field:'ShippingDate',type:'date',hidden:false,caption:'Ship Dates'} ] });
w2ui['C9XTvNvQ_grid'].add([ { recid:1,Amount: '106762.1600000000',Author: 'Kerry Burns',Country: 'Finland',Instock: '0',ShippingDate: '2015/12/31', selected :false, hidden : false, summary : false, editable : true}, { recid:2,Amount: '195201.4600000000',Author: 'Keith Barr',Country: 'Netherlands',Instock: '0',ShippingDate: '2004/09/14', selected :false, hidden : false, summary : false, editable : true}, { recid:3,Amount: '133301.5000000000',Author: 'Colby Bush',Country: 'Syrian Arab Republic',Instock: '1',ShippingDate: '2007/12/27', selected :false, hidden : false, summary : false, editable : true}, { recid:4,Amount: '22837.7200000000',Author: 'Mara Sargent',Country: 'Belize',Instock: '0',ShippingDate: '2004/02/16', selected :false, hidden : false, summary : false, editable : true}, { recid:5,Amount: '61506.4200000000',Author: 'Dylan Hardy',Country: 'Guinea-bissau',Instock: '0',ShippingDate: '2010/08/06', selected :false, hidden : false, summary : false, editable : true}, { recid:6,Amount: '100985.5500000000',Author: 'Anthony Mcleod',Country: 'Colombia',Instock: '0',ShippingDate: '2011/04/30', selected :false, hidden : false, summary : false, editable : true}, { recid:7,Amount: '21218.8200000000',Author: 'Colt Whitney',Country: 'Lebanon',Instock: '0',ShippingDate: '2003/05/19', selected :false, hidden : false, summary : false, editable : true}, { recid:8,Amount: '52277.6400000000',Author: 'Gemma Boone',Country: 'British Indian Ocean Territory',Instock: '1',ShippingDate: '2004/07/25', selected :false, hidden : false, summary : false, editable : true}, { recid:9,Amount: '18960.6800000000',Author: 'Lesley Mckee',Country: 'Saudi Arabia',Instock: '1',ShippingDate: '2012/09/12', selected :false, hidden : false, summary : false, editable : true}, { recid:10,Amount: '60167.9200000000',Author: 'Howard Baxter',Country: 'Lesotho',Instock: '1',ShippingDate: '2013/02/06', selected :false, hidden : false, summary : false, editable : true} ]);
w2ui['C9XTvNvQ_grid'].refresh(); w2ui['C9XTvNvQ_grid_toolbar'].show('search'); w2ui['C9XTvNvQ_grid_toolbar'].show('save'); w2ui['C9XTvNvQ_grid_toolbar'].show('reload'); w2ui['C9XTvNvQ_grid_toolbar'].show('delete'); w2ui['C9XTvNvQ_grid_toolbar'].show('column-on-off'); w2ui['C9XTvNvQ_grid_toolbar'].show('add'); w2ui['C9XTvNvQ_grid_toolbar'].show('search-advanced');
Try to sort by Amount Field. See picture ....
I forgot to mention, that I am using the latest github version
Got it. The problem is that you need to use in JSON numbers not strings, if you want to sort as number, so instead of
{ recid:1,Amount: '106762.1600000000',Author: 'Kerry Burns',Country: 'Finland',Instock: '0', ShippingDate: '2015/12/31', selected :false, hidden : false, summary : false, editable : true},
use
{ recid:1,Amount: 106762.1600000000,Author: 'Kerry Burns',Country: 'Finland',Instock: '0', ShippingDate: '2015/12/31', selected :false, hidden : false, summary : false, editable : true},
Where amount is not enclosed in single quotes.
Confirmed . Thanks
@rsaungc You could probably write your own sort function, based on PR #1504
When you sort a date or number columns, it is sorting as a string,