DOM, Can't set object names for row
DOM, Can't set object names for row
1DMF
Posts: 16Questions: 5Answers: 0
Hi,
I seem to be going round in circles trying to set names for the columns so .row() returns an object and not an array.
I have this HTML
<table id="uploads">
<thead>
<tr>
<th>DocID</th>
<th>Date</th>
<th>Type</th>
<th>Description</th>
<th>User</th>
</tr>
</thead>
<tbody>
<tmpl_loop name='cpd_uploads'>
<tr>
<td><tmpl_var name='DocID'></td>
<td><tmpl_var name='UDate'></td>
<td><tmpl_var name='File_Ext'></td>
<td><tmpl_var name='Description'></td>
<td><tmpl_var name='User_Name'></td>
</tr>
</tmpl_loop>
</tbody>
</table>
but when I try to initialise it with...
UPLOAD = $('#uploads').DataTable({
"sDom": 'R<"H"fr>t<"F"ip>',
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"iDisplayLength": 5,
"columns": [
{ "data": "DocID" },
{ "data": "UDate" },
{ "data": "File_Ext" },
{ "data": "Description" },
{ "data": "User_Name" }
],
"aoColumnDefs": [
{"sType":"uk_date", "aTargets":[1], "sWidth":"90px",},
{"sWidth":"90px", "aTargets":[2]},
{"sWidth":"200px", "aTargets":[4]}
],
"order": [[ 1, "desc" ]],
"oLanguage": {
"sEmptyTable": "You do not have any uploaded documents. Use form below to add one."
},
});
I get an error (warning)...
DataTables warning: table id=uploads - Requested unknown parameter 'DocID' for row 0.
If I leave out the columns property, it works fine only I get an array not an object.
I don't understand what I'm doing wrong?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
"data" corresponds to a variable in the passed object. So each row object should have variables: DocID, UDate, File_Ext, Description, User_Name.
Can you please paste the source data so we can see what it looks like?
I did paste the source data it's a DOM table.
ahh ok well if you want to use objects, then you have to use https://datatables.net/reference/api/row.add() to add an object with the aforementioned variables. Then when you use https://datatables.net/reference/api/row().data() , it will return the object used.
Sorry I still don't understand. I don't want to add any data, the template has already does that.
The datatables object is populated with the data via a normal HTML DOM table.
But I want row() to return {object} NOT [array].
The docs say : https://datatables.net/examples/advanced_init/object_dom_read.html
But when I use the example syntax I'm getting that error?
MY bad i misunderstood what you were asking.
First, that page mentions "Please note that this feature requires DataTables 1.10.3 or newer." So are you? If so, try removing everything except the "columns" declaration so that your code matches the example. If that works then begin re-adding each option until you figure out which one broke it.
Once you have everything working, to get the data you have some options:
I believe I got an example working http://live.datatables.net/qoqemata/1/edit?html,js,console,output
Use
columns.data
. If it is a DOM sourced table and you usecolumns.data
to assign object names, DataTables will write them into those object names rather than an array. Example.Allan