Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested object array search (Question) #43

Closed
lnkpaulo opened this issue Sep 29, 2015 · 2 comments
Closed

Nested object array search (Question) #43

lnkpaulo opened this issue Sep 29, 2015 · 2 comments

Comments

@lnkpaulo
Copy link

Hi,

First of all thank you for the excellent plugin.

I have a problem when I'm working with nested objects with arrays. My model is:

...
loc: [{
    type: {
      type: String,
      default: 'Feature'
    },
    properties: {
      country: {
        type: String,
        default: 'nd'
      },
      status: {
        type: Number,
        default: '0'
      },
      modifiedAt: Date
    },
    geometry: {
      type: {
        type: String,
        default: 'Point'
      },
      coordinates: {
        type: [Number],
        index: '2dsphere'
      }
    }
  }]
...

and my goal is to retrieve, e.g. loc.properties.country, however I cannot see any info in my tables.
Please see my debug info:

Query: { draw: '1',
  columns:
   [ { data: 'loc.properties.country',
       name: '',
       searchable: 'true',
       orderable: 'true',
       search: [Object] } ],
  order: [ { column: '0', dir: 'asc' } ],
  start: '0',
  length: '10',
  search: { value: '', regex: 'false' },
  _: '1443568143064' }
Search Criteria builded: { options:
   { handlers: { field: { arrayPath: 'loc' } },
     conditions: { username: 'donald' } },
  pageStart: 0,
  pageSize: 10,
  nbColumns: 1,
  search: undefined,
  fields:
   [ Field {
       index: 0,
       model: 'users',
       path: 'loc.properties.country',
       searchable: true,
       search: undefined,
       sortable: true,
       sort: { dir: 'asc', precedence: 0 },
       selectable: true,
       type: 'String',
       ref: undefined,
       refType: undefined,
       arrayType: undefined,
       base: undefined,
       arrayPath: 'loc' } ],
  select: { 'loc.properties.country': 1 },
  sort: { 'loc.properties.country': 'asc' },
  conditions: { '$and': [ { username: 'donald' } ] },
  populate: [] }
Data: { draw: '1',
  recordsTotal: 1,
  recordsFiltered: 1,
  data:
   [ { _id: 5605528705fa0cd019316360,
       loc:
        [ { properties: { country: 'none' } },
          { properties: { country: 'France' } },
          { properties: { country: 'France' } },
          { properties: { country: 'France' } },
          { properties: { country: 'France' } },
          { properties: { country: 'France' } },
          { properties: { country: 'France' } },
          { properties: { country: 'France' } },
          { properties: { country: 'France' } },
          { properties: { country: 'France' } },
          { properties: { country: 'France' } },
          { properties: { country: 'France' } },
          { properties: { country: 'France' } },
          { properties: { country: 'France' } },
          { properties: { country: 'France' } },
          { properties: { country: 'France' } },
          { properties: { country: 'France' } },
          { properties: { country: 'France' } } ] } ] }

How I can pass the right data to datatables?

Thanks.

@eherve
Copy link
Owner

eherve commented Sep 30, 2015

Hi,

Your are getting the country and it is sent to DataTable. But on DataTable cannot retireve the value sent on the field 'loc.properties.country' because loc is an array and DataTable do not allow 'loc.'properties'.

You need to use a renderer on the field (like in the test package with the module) and process manually the data:

 { data: "loc.properties.country", defaultContent: "",
        render: function(data, type, full) {
                    return JSON.stringify(full.loc); }
      }

I hope this helps

Regards

@lnkpaulo
Copy link
Author

Hi,

Thank you for the quick answer and the hint.
I was trying to avoid process the data manually but it seems for now it is the solution.

Once more thanks for the excellent plug-in.

Regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants