How do I add class name obtained from server to all rows?

How do I add class name obtained from server to all rows?

bcraigbcraig Posts: 8Questions: 2Answers: 0

I have a checkbox that once clicked will hide all rows with a certain class name throughout all the datatable pages.

My datatable data is fetched serverside and I want each datatable row to obtain its class name from its corresponding database row. I'm just not sure how to add the class name.

My php script echos

{
"data": [
"DT_RowClass" : $row['status'],
"",
"$row['name']",
"$row['status']",
]
}

But then my table just says 'Loading' and no data shows.

Answers

  • bcraigbcraig Posts: 8Questions: 2Answers: 0

    This is my datatable code

    var oTable = $('#stockTable').DataTable({ 
        "serverSide": false, 
        "ajax": "stockTable.php", 
        "sDom": 'ltipr',
        "infoEmpty": "No entries to show", 
        "aaSorting": [ ], 
        'aoColumns': [{
            'sTitle': '<input type="checkbox" id="checkAll">',
            'mRender': function() { return '<input class="check" type="checkbox" name="">';
                    }, }, null, null, null, null, null, null, null],
        "aoColumnDefs": [{ "bSortable": false, "aTargets": [ 0 ]}], 
        "fnDrawCallback": function( oSettings ) {
            var notCheckedNum = $('tbody td :checkbox:not(:checked)').length;
            var isCheckedNum = $('tbody td :checkbox:checked').length;
            if(notCheckedNum>0) $('#checkAll').prop('checked', false); else $('#checkAll').prop('checked', true);
        } , "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
             var rowClass = aData[6];
             var string = rowClass.replace("/", "");
             $(nRow).addClass(string);
            }
        });
        $.fn.dataTableExt.afnFiltering.push(
            function( oSettings, aData, iDataIndex ) {
              var nTr = oSettings.aoData[ iDataIndex ].nTr;
              if (($(nTr).hasClass('takenstock') || $(nTr).hasClass('takenSOLD')) && $('#hideTaken').is(':checked')) return false;
              else return true;
            }
        );
    
  • bcraigbcraig Posts: 8Questions: 2Answers: 0
    edited July 2014

    I have created an example here..

    http://live.datatables.net/egagaz/23/edit?js,output

    This example only applies the row class name to the rows on the current page in view not the entire data set.

This discussion has been closed.