I have a single column table that displays 10 results per page using datatables 1.9.4. The table is being populated by the dataTable ajax method. I can render one value per row but I will need to be able to render multiple values per row. (Think 1 row = 1 array in the json object.)
How can I take an array of objects and render that array of objects into a single column?
I've read up on column rendering and object arrays. I'm having no luck.
e.g.
A row, once rendered, would look like this:
<tr>
<td>
<a href="[email protected]" class="mail">Email Product</a> <!-- this would come from product_email -->
<h3><a href="#">Product1</a></h3> <!-- this would come from product_name -->
<p class="description">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sequi, a, similique, fugit, ratione facere eius mollitia quo illo quos minus laborum suscipit vel nesciunt totam debitis? Nihil, rerum non sed.</p> <!-- this would come from product_description -->
</td>
</tr>
Here's what my data looks like (trimmed down):
{
data: [
{
product_email: "[email protected]",
product_name: "Product1",
priduct_description: "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sequi, a, similique, fugit, ratione facere eius mollitia quo illo quos minus laborum suscipit vel nesciunt totam debitis? Nihil, rerum non sed."
},
{
product_email: "[email protected]",
product_name: "Product2",
priduct_description: "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sequi, a, similique, fugit, ratione facere eius mollitia quo illo quos minus laborum suscipit vel nesciunt totam debitis? Nihil, rerum non sed."
},
{
product_email: "[email protected]",
product_name: "Product3",
priduct_description: "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sequi, a, similique, fugit, ratione facere eius mollitia quo illo quos minus laborum suscipit vel nesciunt totam debitis? Nihil, rerum non sed."
}
]
}
Here is my call to dataTables
this.$el.find('table').dataTable({
sDom: '<"top">rt<"bottom"<"showing"i><"product-length"l><"product-pagination unlist horizontal"p>><"clear">',
sPaginationType: 'full_numbers',
oLanguage: {
oPaginate: {
sFirst: '<<',
sLast: '>>',
sNext: '>',
sPrevious: '<'
}
},
bProcessing: true,
bServerSide: true,
sAjaxSource: 'products.php',
/*columns: [
{ data: '[]' }
],*/
fnServerData: function(sSource, aoData, fnCallback) {
console.log(sSource, aoData, fnCallback);
}
});
$('#example').dataTable({"ajax": 'products.php'} );....did it draw the table correctly??Uncaught TypeError: Cannot read property 'length' of undefined. I think it's yelling at me because it's expecting only an array, not an array of objects.$('#yourTableID').dataTable({"ajax": 'products.php'});....and remember, your table have to have atheadand atbodyin order to work properly with dataTables :)