jquery datatable - How to use render function get

2019-06-03 11:39发布

问题:

I have add button in each row ,but I want to check if info column data is N/A, then not shown the button, I have try to set render as below in my code ,but it's not work

{
    "targets": -1,
    "data": null,
    "render": function ( data, type, row ) 
    {
        if (row.info != 'N/A') {
        return "<button href='" + row.index() + "' class='btn btn-info'>View</button>"
        } else { return "" }
     }
    }                    
}

Any help/advice is greatly appreciated. Willing to post any more information if it will help.

回答1:

Working Link Here

"render": function(data, type, full, meta ) {
    if (full.info != 'N/A') {
        return "<button href='" + row.index() + "' class='btn btn-info'>View</button>"
    } else {
        return ""
    }
}


回答2:

Render is documented here: https://datatables.net/reference/option/columns.render

You aren't using the same name of arguments documented there, but in the examples, you would use full to access all of the available columns and data is the current column. I'm not sure where you got field from. So data from info would be accessed at full.info.

An example being:

"render": function ( data, type, full, meta ) {
  return '<a href="'+data+'">' + full.info + '</a>';
}