Question about invalidating and re-drawing rows customized via createdRow option
Question about invalidating and re-drawing rows customized via createdRow option
I have a DataTable instance that is loaded via AJAX, and using the createdRow
, the values of the td
cells will be altered into links, as well as some attributes being added to both the tr
and td
. When the value gets modified, then I need to row().invalidate()
the row.
The question I had, was how can I have all of the JS thats ran via the createdRow
, run again on the row that just got invalidated?
Heres the jQuery, just to give you a better idea of what im working with :
function do_datatable(data_src){
// Static columns
var columns = [
{ data: 'creator' },
{ data: 'created' },
{ data: 'modifier' },
{ data: 'modified' }
];
// Compile the dynamic columns
$.each(data_src.partition.visible_fields, function(f_name, f_data){
columns.push({data: f_name});
});
// Initiate the DT
$('#data-table').DataTable( {
//ajax: {url: "/REST/partition/assets/partition_id/1/format/json", dataSrc: "assets"},
data: data_src.assets,
deferRender: true,
columns: columns,
initComplete: function( settings, json ) {
// Initialize the Editable, hand down the DT instance for event handling
assets.editable(this);
},
createdRow: function( row, data, dataIndex ) {
var f_name, field, type, td, editable, truncated;
// Adding attributes to the <TR>
$(row).attr('data-row-id', data.asset_id);
$.each(columns, function(k,c){
f_name = c.data;
td = $( row ).find( 'td' ).eq( k );
// Adding attributes to the <TD>
td.attr('data-field', f_name);
editable = $( '<a>', {
'id': f_name,
'data-title': "Enter " + field.name,
'data-value': td.text(),
'class': 'string-edit',
'data-field-type': type,
'text': td.text(),
'placeholder': field.placeholder,
'href': '#'
} );
td.html(editable);
});
}
} );
}
Thanks!.. Again
P.S. I know I ask a lot of questions, im just heavily relying on DataTables for this Open Source project, I try to pay back by helping in the forums myself when I can.
This question has an accepted answers - jump to answer
Answers
I was playing around with both the Javascript data source (local JSON), and AJAX data source (As you can probably see from the
ajax
setting commented out), and I found that if I use AJAX, and run theajax.reload()
, then I dont need to invalidate it, and it runs everything in thecreatedRow
.So I guess that solves it, but is there a way to run
ajax.reload()
on just specific rows? If I have a ton of rows, I dont want it to try and update all of them.Currently you need to have it in a function that is called both by
createdRow
and by whatever is doing the update.createdRow
will only ever run once in the life time or a row and there is currently no update event (something that will be added int he next major version).No - you would need to make your own Ajax call and then use
rows().remove()
androws.add()
to delete and then add the rows required - which is basically whatajax.reload()
does, just for all rows.Allan