vitmalina / w2ui

UI widgets for modern apps. Data table, forms, toolbars, sidebar, tabs, tooltips, popups. All under 120kb (gzipped).
http://w2ui.com
MIT License
2.66k stars 729 forks source link

Sort on Date or number fields, it is not working correctly #270

Closed avacondios closed 11 years ago

avacondios commented 11 years ago

When you sort a date or number columns, it is sorting as a string,

vitmalina commented 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.

avacondios commented 11 years ago

With yyyy/mm/dd, the date field is working. But for numbers, not . For example, 19 is greater than 1750.

vitmalina commented 11 years ago

Can you please send me your JSON file

avacondios commented 11 years ago

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');

avacondios commented 11 years ago

Try to sort by Amount Field. See picture ....

w2grid

avacondios commented 11 years ago

I forgot to mention, that I am using the latest github version

vitmalina commented 11 years ago

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.

avacondios commented 11 years ago

Confirmed . Thanks

rsaungc commented 6 years ago

Sorry to add new item to this issue.

How about numbers with link? For example,

1 2 3 14

If I sort that column, "14" will be between "1" and "2"

it won't solve correctly for these links.

mpf82 commented 6 years ago

@rsaungc You could probably write your own sort function, based on PR #1504