Maximum size/length of data-order?

Maximum size/length of data-order?

stefanvhstefanvh Posts: 11Questions: 4Answers: 0

I’m about to troubleshoot a sorting issue using datatables, and was wondering if there are any limitations to this attribute.

Originally i set the data-order value the datetime’s ticks value but changed this to yyyyMMddHHmm to check if that helped.

I set the data-order attribute like this:

columnDefs: [
{
targets: 1,
createdCell: function (td, cellData, rowData, row, col) {
$(td).attr('data-order', rowData.CreatedTicks);
}
}]

This table is fully populated by ajax data and does not have server-side processing.

So, before i proceed, are there any limitations i should know of?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770

    I might be wrong but I remember reading other threads stating that the HTNL 5 data attributes for sorting and searching need to be in place before initializing Datatables. They will be read from the DOM during init. Datatables won't use them if adding them after initialization which it looks like you are doing.

    You can use the sort operation of columns.render to manipulate the data Datatables uses to sort with. Its described here:
    https://datatables.net/manual/data/orthogonal-data

    This blog describes another way to sort by dates. It might be a better optoin depending on your goals.
    https://datatables.net/blog/2014-12-18

    Kevin

  • stefanvhstefanvh Posts: 11Questions: 4Answers: 0

    I am using objects as a data source (i specify te data value), but I do not have several levels like the example.

    I tried another approach using render, but it does not work.

                            {
                                data: 'CreatedTicks',
                                render: function (data, type, row, meta) {
                                    return row.Created;
                                }
                            },
    
  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770

    Its hard to say what to do without actually seeing an example of what you have. Please post a link to your page or a test case replicating the issue.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • stefanvhstefanvh Posts: 11Questions: 4Answers: 0

    I understand. I'm not sure how to provide an example which has an ajax datasource however.

    Do you know of any example or reference where all the data is loaded using ajax and there is custom sorting applied?

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770
    Answer ✓

    Datatables has some ajax loaded templates you can start from, info here:
    https://datatables.net/manual/tech-notes/9#Ajax-loaded-data

    However for your particular case we don't need to have ajax loaded data. Instead of using ajax you can create a Javascript variable that contains an example of the data and use data to load the data. the test case doesn't need to replicate everything. It just needs to replicate what we need to help with.

    Here is a simple example:
    http://live.datatables.net/cebagiru/1/edit

    It has two columns with the same data. One column is rendered to manipulate the sorted data. The goal is to sort by the number, for example the data 1B02 will sort as 102. The example also shows the rendered sort data in parenthesis. Compare the sorting of the two columns. It will make more sense when you look at it :-)

    Kevin

  • stefanvhstefanvh Posts: 11Questions: 4Answers: 0

    Thanks for pointing me in the right direction.

    The solution was to only handle the 'display' type in the render function.

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770

    BTW, I forgot that I came up with a way to use data-order with dynamic data. Here is the example if you are still interested:
    http://live.datatables.net/fezetule/1/edit

    Kevin

This discussion has been closed.