meteor-tabular
meteor-tabular copied to clipboard
Sorting nested array results with data: [, ] syntax not working
Aldeed, first of all, you rock worlds as I've used this package in almost all meteor applications I've created and it's a true dream to use!! Users love it!!
I've had absolutely zero issues with the package until recently. The issue is related to sorting on results of nested arrays. Just to make sure I wasn't loosing my mind, I created a bare bones non-meteor html page using just [email protected] and a fresh download of jquery.dataTables.js. In this test page, creating the datatable in the exact same way is sorting as expected.
I'm very familiar with using the render method on columns for sorting, type, filter, and display. I use this a lot. I've played with every possible way I could think of trying to use different data types for sorting with no luck.
Below is the bare bones datatable creation that is working (sorting) as expected. Notice data: 'sales[,].roles[, ]' in the second column definition. This syntax displays the desired results but I'm not able to sort in Tabular when creating a table this same way.
<table id="arrayTester" class="table">
<thead>
<tr>
<th>name</th>
<th>roles</th>
</tr>
</thead>
</table>
var users = [{
"name": "user1",
"sales": [
{
"saleId": "KnGEBroj4Wc2CkyNG",
"roles": [
"consignor"
]
}
]
},
{
"name": "user2",
"sales": [
{
"saleId": "KnGEBroj4Wc2CkyNG",
"roles": [
"vendor"
]
}
]
},
{
"name": "user3",
"sales": [
{
"saleId": "KnGEBroj4Wc2CkyNG",
"roles": [
"consignor",
"vendor"
]
}
]
}];
$('#arrayTester').dataTable({
data: users,
columns: [
{
data: 'name'
},
{
data: 'sales[,].roles[, ]'
}
]
});
As I mentioned, building this exact table with Tabular.Table does not sort on the roles column. In case it matters, for this particular table, the source collection is Meteor.users. If this db wasn't already in production, I would go as far to restructure the "sales" array in Meteor.users to make this work...but it's too late for that. Please let me know your thoughts. Thank you for your time! And once again, you rock!!
I have the same issue with the Meteor.users collection. I want to display/sort /search on first email address so I have this
columns: [
{
data: 'emails.[,].address',
title: 'Emails de vos salariés',
},
...
]
The data are loaded but no sort nor search on emails address :(
I also tried data: 'emails.[0].address', without better results
Edit: I can search emails if I give this as data for the column emails[0].address but still no sort :(
I recently ran across this issue and was able to solve it using dot object notation. https://datatables.net/release-datatables/examples/ajax/objects_subarrays.html
columns: [
{
data: 'emails.0.address',
title: 'Emails de vos salariés',
},
]
Proper order asc/desc and search within the results just like one would expect. Hope this helps somebody. Cheers