row.add() and DT_RowID with dom table?
row.add() and DT_RowID with dom table?
mihomes
Posts: 165Questions: 23Answers: 0
When adding a row to a dom table using row.add() how can I specify the DT_RowID for it?
[code]
"columns": [
{
"searchable": false,
"sortable": false
},
/* 1 filename*/ null,
/* 2 filesize*/ null,
/* 3 timestamp*/ null
],
//Example row creation with php in the dom. I add the rowid manually here.
echo '
'.$file.'
'.formatSizeUnits($filesize).'
'.$filetime.'
';
//Now say I want to add a row to the table. Since this is dom I need to manually add it and draw the table afterwards.
dt.row.add( [
'td0',
'td1',
'td2',
'td3'
] ).draw();
[/code]
[code]
"columns": [
{
"searchable": false,
"sortable": false
},
/* 1 filename*/ null,
/* 2 filesize*/ null,
/* 3 timestamp*/ null
],
//Example row creation with php in the dom. I add the rowid manually here.
echo '
'.$file.'
'.formatSizeUnits($filesize).'
'.$filetime.'
';
//Now say I want to add a row to the table. Since this is dom I need to manually add it and draw the table afterwards.
dt.row.add( [
'td0',
'td1',
'td2',
'td3'
] ).draw();
[/code]
This discussion has been closed.
Replies
[code]
"createdRow": function( row, data, dataIndex ) {
$(row).attr('id', data[1]);
},
[/code]
[code]
// this works and adds the new row to the table
$('#test').on('click', function () {
dt.row.add( [
'td0',
'td1',
'td2',
'td3'
] ).draw();
});
//same code does not work within an ajax response...
$('#dtCreate').on('click', function () {
$.ajax({
type: 'post',
url: '/test/process/p_db_create.php'
}).done(function (response) {
if (response.success)
{
//add the row since this is not serverside
dt.row.add( [
'td0',
'td1',
'td2',
'td3'
] ).draw();
...more code below...
[/code]
It might sound daft, but just specify `DT_RowID` as a property. Obviously you can't do this if you are using an array data source, but if you are using objects, it is that simple.
> Another issue... adding the row is not working inside an ajax response... response returns correctly yet the row is not added.
Looks like it should work. I'd need a test case showing the issue please.
Allan
An example ajax return :
[code]
{
"data":[
{
"DT_RowID":"1398142350",
"checkbox":"",
"filename":"1398142350.sql.gz",
"filesize":"7.57 KB",
"timestamp":"April 22nd, 2014 @ 12:52 am EDT"
},
{
"DT_RowID":"1398143071",
"checkbox":"",
"filename":"1398143071.sql.gz",
"filesize":"7.57 KB",
"timestamp":"April 22nd, 2014 @ 1:04 am EDT"
}
]
}
[/code]
my columns in the initialization :
[code]
"columns": [
{
"data": 'checkbox',
"searchable": false,
"sortable": false,
"class": 'center'
},
{ "data": "filename" },
{ "data": "filesize" },
{ "data": "timestamp" }
],
[/code]
Allan
So I have to change the models that come back from my server to contain DT_RowID?
Is there no other way to specify which column to use for DT_RowID?
please help me
i have:
when a draw the new tr with the nameCat.value, i want it have the id=idInserido..
i test a lot of ways but i can't put this ON :(
How is the way to the new "tr" have a id like "idInserido"?
Tanks
To manipulate the DOM elements you would probably be best to use
columns.createdCell
orcreatedRow
.Allan