V2 Column ordering with edited data

V2 Column ordering with edited data

MattSkeldonMattSkeldon Posts: 19Questions: 1Answers: 0
edited April 2014 in Bug reports
First of all, apologies if this is not the correct place to report bugs for V2 of Datatables, second apologies again if this is not a bug and simply a misunderstanding of implementation.

Unfortuantly I am unable to link to a live version so I have replicated it using the test suite.

http://live.datatables.net/dowameb/1/edit?js,output

As you can see I have modified cell value inside the rowCallback function, doing this does not get taken into account when then ordering that particular column...

I saw in the documentation that you can set orthagonal data using data-sort but again this does not seem to have any effect when doing so (also demonstrated) in the rowCallback function.

In my implementation I am unable to set the order at markup level as I use ajaxsource with an aaData object to return the values to be added to the table.

If I am indeed correct that this is a bug, I am not sure how difficult it would be but perhaps an implementation idea could be to supply two values inside the aaData object

eg...

[code]
{"aaData":[
[
28,
"00011",
"PY/66732",
"Someones Name",
{
display : "ABCD",
order : "SomeValueThatShouldDisplaySecondWhenOrderedAlphabetically"
}
],
[
65,
"00012",
"PY/54356",
"Protected For Integrity",
{
display : "EFGH",
order : "AnotherValueTheShouldDisplayFirstWhenOrderedAlphabetically"
}
]
]}
[/code]

Hopefully this is easy enough to understand, I am relatively new to reporting problems (if as alluded to previously this is a problem at all)

Replies

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    > V2 of Datatables

    There isn't a v2 of DataTables! At least not yet. There might be in a few years...

    The problem you are seeing is that you are manipulating the DOM, but not telling DataTables that you have changed the data. See: http://datatables.net/faqs#append .

    You need to use the API to manipulate the table if you want DataTables to be aware of the changes you are making - otherwise it can't know that the data has changed!

    Allan
  • MattSkeldonMattSkeldon Posts: 19Questions: 1Answers: 0
    My bad, v1.10.

    I could have swore I edited values on rowCallback before to manipulate what the server sent and what was displayed on screen (which at the time worked beautifully), I can't find any examples though so will have to roll with it, regards :)
  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    You really don't want to use the API in rowCallback - that would kill performance stone dead. If you want to alter the value that is visible in the cell, or for sorting etc, use the `render` option: http://next.datatables.net/reference/option/columns.render

    Allan
  • MattSkeldonMattSkeldon Posts: 19Questions: 1Answers: 0
    Wow, column render, how have I never seen that before?

    So previously I was modifying the cell values in the rowCallback function like so

    [code]
    "rowCallback" : function(nRow, aData){
    var $row = $(nRow).data("pID", aData[0]);
    switch (aData[7]) {
    case 0: //Clocked in
    $("td:eq(6)", nRow).html("In");
    $row.addClass("in");
    break;
    case 1: //Clocked out (Fall through)
    case 2: //Absence booked
    $("td:eq(6)", nRow).html("Out");
    $row.addClass("out");
    break;
    case 3: //Pending
    $("td:eq(6)", nRow).html("Pending");
    $row.addClass("pending");
    break;
    case 4: //Unknown
    $("td:eq(6)", nRow).html("Unknown");
    $row.addClass("unknown");
    break;
    }
    }
    [/code]

    How would one change the row class and row.data() etc or should this still be done on the rowCallback?

    Regards Matt Skeldon
  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    edited April 2014
    You would use `createdCell` for modifying the class name (you could use `rowCallback` , but `createdCell` is far more efficient).

    Allan
This discussion has been closed.