LumaPictures / meteor-jquery-datatables

Sort, page, and filter millions of records reactively.
http://jquery-datatables.meteor.com
MIT License
98 stars 29 forks source link

Search Properties of Nested Arrays #10

Closed gjolund closed 10 years ago

gjolund commented 10 years ago

Currently properties of nested arrays can be displayed using an mData method instead of assigning the property key directly.

mData: ( rawData, call ) ->
  max = "null"
  if _.isArray rawData.someArray
    rawData.someArray.forEach ( doc ) ->
      if doc.someProperty
        if doc.someProperty > max or max is "null"
          max = doc.someProperty
  return max

This should be cleaned up and abstracted away from the config object, and prepare the global search query to search the nested arrays for that property.

Nomeasmo commented 10 years ago

To me it works, at least in my case.

My data looks like:

        "started": "2014-04-29T17:49:00.358Z",
        "task": [
            {
                "name": "bad guy",
                "jobData": null
            }
        ]}

If I use a column description with mRender, that ensures to return an empty string or my value, it runs smoothly.

        columns: [
            {
                sTitle: "Name",
                mData: "task.name",
                mRender: function (dataSource, call, rawData) {
...  
              }
            },
            {
                sTitle: "Job Data",
                mData: "task.jobData",
                mRender: function (dataSource, call, rawData) {
...
                }
            }
        ]

mRender needs to make sure, that it does not return null or undefined otherwise an alert will show up. Also sorting and search runs as I'd expect.

gjolund commented 10 years ago

Awesome, I love it when things just work. Please let me know if you run into any problems.