problems with editing although idSrc, rowId are set
problems with editing although idSrc, rowId are set
I have 2 tables company and contact. Company has a numeric id as primary key and everything is working. But contact has as primary key company (the id from the company table) + name (of the contact person). If the user selects a company in the company table, in a second table the coresponding contacts are shown. That is working, but for editing it shows "Unable to find row identifier", but rowId and idSrc are set and they are unique for the shown entries in the contact table, because only the contacts of the selected company are shown. With the select column I can't move id.name as the first column.
contactTable = $('#contactTable').DataTable( {
dom: "Blfrtip",
...
rowId: "id.name",
idSrc: "id.name",
columns: [
{ data: null,
defaultContent: '',
className: 'select-checkbox',
orderable: false,
},
{ title: "Name",
data: "id.name"
},
{ title: "Company",
data: "id.company",
visible: false
},
{ title: "Department",
data: "department"
},
...
],
...
});
I can see in the table on the page, that the name is used as row id:
<tr id="Mr. Andreas Fries" role="row" class="odd selected"><td class="select-checkbox sorting_1"></td><td>Mr. Andreas Fries</td><td>xx</td><td>xx@xx</td><td>xx</td><td>xx</td><td></td></tr>
You wrote in https://datatables.net/manual/tech-notes/14 that it could be a combination of fields, too, but I don't know how to use a combination.
Unfortunately it is not possible to send you a link, becuase it is an internal application, but I could create debug information, if that could help.
Thanks for Information.
This question has an accepted answers - jump to answer
Answers
I fear the problem occurs because name includes blancs. what can I do in this situation?
If id.name includes blanks it's not suitable to be used as idSrc as the the data element must have value and be unique.
I tried to use as identifier
instead, but I get the information "row.index is not a function"
I understood that I only need a unique row id for the editor. With
I get row ids:
<tr id="10" role="row" class="odd"><td class="sorting_1">Mr. Krauß</td><td>xx</td><td></td><td>xx</td><td></td><td></td></tr>
but I fear I need the same if idSrc, because the error message is still "Unable to find row identifier". And which arguments have the function, if I use idSrc: function(...){}?
both values of idSrc and rowId need to be the same. Can I insert a not visible dummy column with the row index? How can I do that?
I could create a dummy column in front of the data columns, but without setting rowId and idSrc, it is not taken as key for editor. But it isn't used as row id if I try to set rowId and idSrc to this column, too.
"no" is set to 0, before the data is loaded.
I tried it instead of rendering with the function as data, too. Result is the same, the column is ok, but not used as the key.
Is it not possible to use a dummy column to be able to edit the data? How can I solve that without changing the real data table?
This is an Editor property. It needs to be in your Editor options, not the DataTable options. Without it, Editor is using the default of
DT_RowId
, which is what is causing the issue.Allan
with id.name it don't work, because name includes blancs, that is what I used first. But I think with this dummy column with a kind of line numbers, should work. But it don't use rowNo as id for the row.
You should have
rowId
andidSrc
point to the property in your data source objects that contain the primary key value for the database table, so each row can be uniquely identified to the server.Allan
But the primary key is id.name+id.company and I didn't find a hint how to use a combination as rowId and idSrc.
If you are using the PHP or .NET libraries for Editor, information on using a compound key can be found here.
If you are using your own server-side software you would need to combine the values at the server-side since a DOM element can only have a single id attribute.
Allan
thanks for the information