mapping column names to list of string values?
mapping column names to list of string values?
Rushdy
Posts: 7Questions: 2Answers: 0
<
table id=”stockList”>
<thead>
<tr>
<th>Product Code</th>
<th>Product Descrip</th>
<th>price </th>
<th>qty</th>
</tr>
</thead>
<
table>
Return data { [“prd123”,”pen”,”£1.5”,”500”], [“prd124”,”pen2”,”£2”,”800”], [“prd125”,”pen”,”£1.5”,”500”], [“prd1297”,”pen”,”£1.5”,”500”]}
How do I set the column names to map my object values (marked in ????? below)
- 2. $(document).ready(function () { 3. $("#myTable").DataTable({ 4. "processing": true, 5. "serverSide": true, 6. "filter": false, 7. "orderMulti": false, 8. "ajax": { 9. "url": "/home/LoadData", 10. "type": "POST", 11. "datatype": "json" 12. }, 13. "columns": [ 14. { "data": "??????", "name": " ProductCode ", "autoWidth": true }, 15. { "data": "?????", "name": " ProductDescrip ", "autoWidth": true }, 16. { "data": "?????", "name": " price ", "autoWidth": true }, 17. { "data": "?????", "name": " qty ", "autoWidth": true }, 18. 19. }); 20. }); 21.
Appreciate your help
This discussion has been closed.
Answers
<
table id=”stockList”>
<thead>
<tr>
<th>Product Code</th>
<th>Product Descrip</th>
<th>price </th>
<th>qty</th>
</tr>
</thead>
<
table>
Return data { [“prd123”,”pen”,”£1.5”,”500”], [“prd124”,”pen2”,”£2”,”800”], [“prd125”,”pen”,”£1.5”,”500”], [“prd1297”,”pen”,”£1.5”,”500”]}
How do I set the column names to map my object values (marked in ????? below)
Appreciate your help
In your case I don't believe you need to use
columns
. If your return array is always in the same sequence as your thead, DataTables will map returnArr[x] to associated x columnshouldn't i have to have column name to search on field ?
Yes you are correct. Or you could add them as classes to the th elements. Try it with data removed. Let me know what result is.
The
columns.name
property is only useful for column selection (column-selector
). It has no other use and I've thought of dropping it many times (although it can actually be useful as a column selector, so I won't!).You have arrays as that data source, so you don't need to define
columns.data
(assuming the array order is in the column order). It would be worth reading over the data source section of the manual.Allan