orthogonal and data-order not working together

orthogonal and data-order not working together

idris_bengaliidris_bengali Posts: 20Questions: 3Answers: 1

have a set of "columns": [
{ "data": "Status" },
{ "data": "Location" },
{ "data": "Entity" },
{ "data": "Date" },
],

have set a data-order tag for the Date field

              <TD align="center" class="StdText" data-order=<!$MG_ORDER_DATE_SORT>><!$MG_DATE></TD>

viewing the source shows the tag value in YYYYMMDD format

              <TD align="center" class="StdText" data-order=20120113>01/13/2012</TD>

sadly the sort does not work. it sorts as per the displayed date which is MM/DD/YYYY

When I delete the "columns": section from the html the sort works, but then, I need that definition for the purpose of export..

what do I need to do, to make the sort work?

I have other reports with data-order tags for date fields and the sorting works fine, but those reports do not have the orthogonal data definition.

Thanks

Idris

Replies

  • kthorngrenkthorngren Posts: 21,242Questions: 26Answers: 4,929

    I don't have many data points in this test case:
    http://live.datatables.net/kifiyete/1/edit

    But it does seem to work. Maybe you can update the test case to replicate your issue.

    Kevin

  • idris_bengaliidris_bengali Posts: 20Questions: 3Answers: 1

    Here is clone of the link you provided. I have made edits to closely reflect what we have on site. was able to replicate the sorting issue , column 8 Date.

    Please ignore the jpg/gif not found errors.

    Here is the url http://live.datatables.net/yiguwede/1/edit

    I had earlier tried putting the data-order date value yyymmdd in double qutoes and currently it is without double quotes. neither work.

    Thank you for your attention.

    Idris

  • kthorngrenkthorngren Posts: 21,242Questions: 26Answers: 4,929
    edited December 2018

    Thanks for the test case. I simplified it by copying your date column into my test case. It worked as expected. I tried copying a few things from yours to mine and found that when columns.data is applied the sort order doesn't work. Found this thread that explains why:
    https://datatables.net/forums/discussion/comment/104876/#Comment_104876

    Basically columns.data causes Datatables to not auto-detect the HTML5 parameters since the data is defined with columns.data.
    http://live.datatables.net/kifiyete/6/edit

    I put a simple columns.render function to sort by using Date.parse(). It seems to work for your case. Try removing the columns.render and you will see it sort by the string. Another alternative is to use the technique described in the Ultimate date/time sorting blog.

    Or you can remove columns.data but then you won't be able to access the row data using object notation. You will need to access as arrays.

    Kevin

  • idris_bengaliidris_bengali Posts: 20Questions: 3Answers: 1

    thank you KT

    I adopted the Date.parse() syntax and the sorting works like a charm.

    Idris

This discussion has been closed.