sorting - Ordering a Rails DataTable column by another value -


i building helpdesk application. have model called ticketdetail, table uses datatables data via json. in order periodically recalculate time ticket has been open. time taken formatted simple helper it's in format "dd:hh:mm", should sorted time (stored decimal) multiplied weighting. here's datatables definition

var table = $('#ticket_details').datatable({  order: [[ 8, "desc" ], [ 9, "desc" ], [ 2, "asc" ]],  statesave: true,  deferrender: true,  ajax: $('#ticket_details').data('source'),  "columns": [  { "data": "reference_number" },  { "data": "location" },  { "data": "title" },  { "data": "parent", classname: "hidden-md hidden-sm hidden-xs" },  { "data": { _:"time_display.time", sort: "time_display.decimal_time"}},  { "data": "created_by", classname: "hidden-md hidden-sm hidden-xs" }  ]  } );   setinterval( function () { table.ajax.reload( null, false ); }, 60000 ); 

here's simplified sample record, ticket has been open 3 days , 6 hours, weighting of x2 (i.e. 3.25 * 2 = 6.5:

{  data: [   {    id: 140,    parent: null,    title: "[",    location: "<a href="/en-gb/stores/123">bond st</a>",    ticket_sla: "16 hours",    reference_number: "<a href="/en-gb/ticket_details/140/edit">1606210001</a>",    ticket_sla_weighting: 2,    time_display: {    time: "<span class = "label label-danger">03:06:00</span>",    decimal_time: 6.5    }  ] } 

the problem datatable sorts correctly if display decimal_time, put formatted time in class, sorts number of days, left of colon. (so 03:06:00 , 03:18:00 not sorted properly).

for date/time sorting in datatable need use it's sorting plug-ins

for example, need include js files :

//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js //cdn.datatables.net/plug-ins/1.10.12/sorting/datetime-moment.js 

and then, in jquery use

$.fn.datatable.moment( 'hh:mm mmm d, yy' ); // pass date time format param 

for deeper reference please check :

sorting plugins

ultimate date / time sorting plugin


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -