Sort of complex render
Sort of complex render
rpmccormick
Posts: 139Questions: 19Answers: 0
My datatable display is fairly complex.
I have spent many hours on many different methods to try to enable date-sorting, and have had no luck. I even tried the moment plugin which would be perfect as I already use moment to render, but I cannot get it to work.
Actually, more perfect than the moment plug-in would just be to let me specify 3 different column values for display vs. sort vs. search.
Here is my display code:
{"data": null, "render": function (data, type, row) {return paintCIN(data.CheckinDate, data.CheckinStatus, data.CheckinType)}},
Here is the function it calls:
function paintCIN(CIDate, CIStat, CIType)
{var Color = "purple";
var CI = moment(CIDate);
var CIT = "<br /> <small><i><span style=\"color: #aaa;\">";
if (CIType == 1) {CIT += "via call</span></i></small>"}
else if (CIType == 2) {CIT += "walk-in</span></i></small>"}
else if (CIType == 3) {CIT += "via web</span></i></small>"}
else if (CIType == 4) {CIT = ""}
else {CIT += CIType + "</span></i></small>"}
if (CIStat == 0) {Color = "red"}
else if (CIStat == 1) {Color = "navy"}
if (moment().diff(CI, 'days') == 0) {Color = "green"}
else if (moment().diff(CI, 'days') > 0) {Color = "#aaa"}
return moment(CIDate).format("[<span style=\"color: " + Color + ";\"><small>]ddd[,</small> <b>]MMM[ ]Do[</b> <small>]YYYY[</small></span>]") + CIT;
}
Here is a sample of the column display:
Fri, Jun 12th 2015
via web
Here is what I tried with the plugin:
$.fn.dataTable.moment( "ddd, MMM Do YYYY" );
And I tried making every possible full combo as well:
$.fn.dataTable.moment( "[<span style=\"color: #aaa;\"><small>]ddd[,</small> <b>]MMM[ ]Do[</b> <small>]YYYY[</small></span>]walk-in</span></i></small>]");
I have also tried to make it sort from a different member of data, and from a different hidden column.
NOTE: This is all on normal client-side tables (I learned that for my SSP tables I have to disable sorting and searching on basically all but one column... or it locks up the mysql server with the length of the query - separate issue, already solved, kinda)
This question has an accepted answers - jump to answer
Answers
Perhaps you can link to a page showing the issue so we can debug it please?
If you are using server-side processing then the Moment plug-in won't help since that is client-side and with server-side processing all the ordering is done at the server-side.
If you are loading data via Ajax for client-side processing I would very much suggest using orthogonal data rather than mixing HTML formatting into the moment plug-in, which looks very complicated and rather fragile.
Allan
This sorting issue is for my non-SSP tables. I use both.
I have tried to use orthogonal data but do not understand... it seems the sort data must be included in your JSON, but I am using your PHP libraries for that and do not know how to add sorting-data.
Really, I already have all the sort-fields in the JSON already... the issue is that my columns are rendered from multiple fields with formatting, and I do not understand how to tell DT just to sort by one of them with no formatting.
EXAMPLE: For a single column in a DT table, checkin-date is rendered with moment on first line of cell, and checkin-type is rendered on second line of cell.
RENDER = moment(data.checkin-date) + <br> + formatType(data.checkin-type).
All I need to do is set SORT = data.checkin-date... how do I do that?
Here is a picture of my table
SORT PICKUP | Pickup Date | Other columns
My goal is to get rid of the SORT PICKUP column, and to make the Pickup Date column sort correctly.
What is
FarePickupTime? Is it an integer timestamp? In which case you could just use that for the sorting value:Allan
Awesome, that worked!
I had tried that method before, but I mistakenly had only tried it on a ServerSide table which didn't work.
I am totally happy I got a solution to the non-SSP tables. Thanks!
Now how can I specify the sort for my SSP tables? Here is an example:
I want the column to display color-coded data from 2 fields, but when they click I the header to sort that column, I want SSP to sort based on the name of one of those fields (WorkStatus). I am using your ssp.class.php...
table.WorkOrders.Lazy.php
Thanks again Allan! -Ryan
So the reason it didn't work for server-side processing is that the
rendermethod is a client-side construct, but with server-side processing the ordering is done at the server-side. Therefore, it is the data at the server that would need to be modified. Thus, you would need to update whatever script you are using at the server-side to cope with orthogonal data - theSSP::simpledemo script is not designed to handle such cases.Allan