i'm using jquery datatables 1.10.4 render table each of rows has bits of information file.
a column in table shows file sizes. when rendered, want column read nnn kb (with "kb" suffix). want user able numeric sort on file size column.
however, while files data array has numbers indicating size of file in bytes, sort functionality seems use rendered value of string, , string sort, not numeric one.
is there easy way declare type of column such sort numeric? i.e. sorting, i'd jquery datatables use values in files array.
if can't declared columndefs specification, easiest sort plugin or function use?
here's have far.
var files = {['name','dir',10240], .... } var sortable_size = function(data, type, full, meta) { return math.floor(full[2]/1024) + " kb"; }; $('#files').datatable({ data: files, pagingtype: 'simple', columndefs: [ { targets:0, render:clickable_message }, { targets:3, render:clickable_attachment }, { targets:2, render:sortable_size, width:'100px', type:'num' } ], // no width col 0 here because causes linewrap in data // , size fields (attachment name can wide well) order:[[1, 'asc']], // col 1 (date), ascending fninitcomplete: function() { $('#attachments').fadein(); } });
th solution simple, when data displayed (type === 'display'), return formatted string, otherwise return data sorted. manual:
the type call data requested -
'filter','display','type'or'sort'.
var sortable_size = function(data, type, full, meta) { if(type === 'display'){ return math.floor(full[2]/1024) + " kb"; } esle { return data; } }; see columns.render more information.
if wouldn't have file size stored in bytes, solution use file size sorting plug-in.
Comments
Post a Comment