2

I wonder if anyone else has faced this problem prior. I am loading data into a DataTable via ajax. I am trying to add custom attribute rel to each rows.

I have found a similar question here but it is loading data directly. I could not figure out how to add the custom attribute.

My initialisation code is:

$('#DataTable').dataTable({
    "bLengthChange": false,
    "bFilter": false,
    "sPaginationType": "full_numbers",
    "bStateSave": true,
    "bProcessing": false,
    "sAjaxSource": "<?php echo site_url().$page_name.'/get_data/'?>",
    "aoColumns": [
                 { "mData": "Column1", sClass: "center "},
                 { "mData": "Column2", sClass: "center "},
                 { "mData": "Column3", sClass: "center "},
                 { "mData": "Column4", sClass: "center "},
                 { "mData": "Column5", sClass: "center "}
                 ]
});

The data rows gets populated. Now the problem is the one or more data may have similar parent so i want to add a custom attribute to find the rows with same parent and take them to edit on double click of any rows.

How can i add the custom attribute?

1 Answer 1

3

Using the fnCreatedRow callback i was able to add custom attribute.

Example:

$(document).ready( function() {
    $('#example').dataTable( {
        "fnCreatedRow": function( nRow, aData, iDataIndex ) {
            // Bold the grade for all 'A' grade browsers
            if ( aData[4] == "A" )
            {
                $('td:eq(4)', nRow).html( '<b>A</b>' );
            }
        }
    });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.