george george - 1 year ago 65
Javascript Question

insert data into specific column cell using datatables jquery

I've searched into the documentation of data tables of how one can add data to the table here but no where I could find a way to insert data into a single cell for a given column. For example, I need sth like:

"columns": [ {target (0), "value which will be inserted"} ]

There is a way to inser data from an array but each section of the array contains values for the whole row ( see here but I need to insert data into different cells in respect with the columns since I don't know the column labels initially. This is because the data will be in json format and first I need to extract the unique dates for each json object. These will be my column headers. And then for each of the objects based on its date I need to put it into the relevant date column. So the logic should be sth like:

if this date column (from the table) == json object date then put it there


Answer Source

It seems like after a lot of researching this feature is not available in DataTables. So that's why I've solved the problem with jQuery. Using the code below I can iterate through a column and insert values in it.

//change 1 to the column at hand
$("#table tr > :nth-child(1)").each(function(index) {
    //skip the column header
    if (index > 0){
        //insert value
        $(this).html("<span class='fixed-size-square'> value to be inserted");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download