Meteor-Community-Packages / Meteor-Community-Packages/meteor-tabular

Sorting nested array results with data: [, ] syntax not working

Open
#402 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
360
Forks
132
PR merge metrics
No merged PRs in 30d

Description

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 jquery@1.11.2 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.

```html



name
roles

```

```javascript
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!!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Use the provided users data and columns configuration as the reproduction, starting with the Tabular.Table setup and comparing it with the working DataTables example. Trace how the nested sales/roles value is handled for sorting; done means the roles column sorts correctly for the shown nested array results.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.