changing column classes after ajax load

changing column classes after ajax load

itchyitchy Posts: 4Questions: 0Answers: 0
edited February 2010 in General
i have a table that i need to change column classes depending on the data values - green cells for positve values and red cells for negative values.

is it possible to change the classes in the last 2 columns to "m-row_pos' if they are greater than 0? and "m-row_neg" if they are less than 0 after load? its a large dataset so i'd rather just load json than build the table serverside.

currently i am calling it like this:

[code]
oTable = $('.sortable').dataTable({
"sAjaxSource": '/myjson_source.php',
"aaSorting" : [[ 1, "desc" ],[ 0, "asc" ]],
"sDom" : '<"top"fl>rt<"bottom"pi<"clear">',
'aoColumns' : [{ "sWidth": "400px", "sClass": "m-row2 m-row2-fade" },
{ "asSorting":["desc","asc"], "sClass": "m-row1" },
{ "asSorting":["desc","asc"], "sClass": "m-row1" },
{ "asSorting":["desc","asc"], "sClass": "m-row1" },
{ "asSorting":["desc","asc"], "sClass": "m-row1" },
{ "asSorting":["desc","asc"], "sClass": "m-row1" },
{ "asSorting":["desc","asc"], "sClass": "m-row3" },
{ "asSorting":["desc","asc"], "sClass": "m-row3" },
{ "asSorting":["desc","asc"], "sClass": "m-row4" },
{ "asSorting":["desc","asc"], "sClass": "m-row4" },
{ "asSorting":["desc","asc"], "sClass": "m-row_zero" },
{ "asSorting":["desc","asc"], "sClass": "m-row_zero" }]
});
[/code]

Replies

  • itchyitchy Posts: 4Questions: 0Answers: 0
    edited February 2010
    i managed to fix myself by calling $.getJSON and modifying the json array to fit as a source for "aaData".

    for reference to anybody else here is my solution:

    [code]
    $.getJSON( '/myjson_source.php', null, function(json){
    oTable = $j('.sortable').dataTable({
    "aaData" : json,
    "aaSorting" : [[ 1, "desc" ],[ 0, "asc" ]],
    "sDom" : '<"top"fl>rt<"bottom"pi<"clear">',
    'aoColumns' : [{ "sWidth": "400px", "sClass": "m-row2 m-row2-fade" },
    { "asSorting":["desc","asc"], "sClass": "m-row1" },
    { "asSorting":["desc","asc"], "sClass": "m-row1" },
    { "asSorting":["desc","asc"], "sClass": "m-row1" },
    { "asSorting":["desc","asc"], "sClass": "m-row1" },
    { "asSorting":["desc","asc"], "sClass": "m-row1" },
    { "asSorting":["desc","asc"], "sClass": "m-row3" },
    { "asSorting":["desc","asc"], "sClass": "m-row3" },
    { "asSorting":["desc","asc"], "sClass": "m-row4" },
    { "asSorting":["desc","asc"], "sClass": "m-row4" },
    { "asSorting":["desc","asc"], "sClass": "net m-row_zero" },
    { "asSorting":["desc","asc"], "sClass": "net m-row_zero" }]
    });
    // add extra jquery here to change classes
    });
    [/code]
This discussion has been closed.