jquery - Put a class depending on the data ajax datatables -
i searched alot , i'm extremely sure can done cannot find way it. use jquery datatables , i'm trying generate class , few javascript action depending on value i'm recieving. example, simple putting red background when unit negative, etc. created css , i'm loading json file via ajax parameters of datatables. here's javascript:
table = $('#activitiestable').datatable({ "ajax": "data.txt", "columns": [ { "data": "id" }, { "data": "description" }, { "data": "type_of_expenditure" }, { "data": "real_cost" } ] });
i know in columns parameters, can set class right after calling "classname" in json, i'm not sure how generate class comparing variable. example, i'd this:
"columns": [ { "data" : "id", "classname": (data.id < 0 ? "negative" : "positive")) } ]
not sure if can done way? or if have check on jquery everytime ajax call launched feel lt initialized right there...
i found can use way:
{ "data": "forcast_profit_loss", "createdcell": function (td, celldata, rowdata, row, col) { if ( celldata < 0 ) { $(td).addclass('number number-negative'); $(td).text(celldata.substr(1)); } else{ $(td).addclass('number number-positive'); } } }
you can find references right there: https://datatables.net/reference/option/columns.createdcell
Comments
Post a Comment