Result List Locator

Result List Locator

top1selecttop1select Posts: 1Questions: 1Answers: 0
edited March 2016 in Free community support

Hi, all

I'm trying to migrate to datatables from this example using YQL:

http://yuilibrary.com/yui/docs/datatable/datatable-dsget.html

It can specify schema like this with resultListLocator:

dataSource.plug(Y.Plugin.DataSourceJSONSchema, {
    schema: {
        resultListLocator: "query.results.Result",
        resultFields: [ "Title", "Phone", "Rating" ]
    }
});

How should I get below Results to work with datatables's Object data source? I tried the nested Object data source example and others, but the Data is always at top level, not suitable for this case:

{
 "query": {
 ...
  "diagnostics": {
   "publiclyCallable": "true",
   "url": {
    "execution-start-time": "1",
...
   },
   "user-time": "68",
  },
  "results": {
   "item": [
    {
     "title": "",
     "description": 
......

I tried this:

```

$('#example').DataTable( {
    "processing": true,
    "serverSide": true,
    "ajax": "scripts/objects.php",
    "columns": [
        { "query.results.item": "title" },
        { "query.results.item": "description" },
        { "query.results.item": "position" },
        { "query.results.item": "office" },
        { "query.results.item": "start_date" },
        { "query.results.item": "salary" }
    ]

Error is:

SyntaxError: missing ; before statement

{"query":{"count":16,"created":"2016-03-30T02:41:49Z","lang":"en-US"

Thanks a lot!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,786Questions: 1Answers: 10,511 Site admin
    Answer ✓

    DataTables expects an array of data - the contents of that array are used to represent each row. So if query.results.item is an array of items (one for each row) you would use ajax.dataSrc to tell DataTables where to get the data - e.g. dataSrc: 'query.results.item'.

    If you don't have a simple plain array of information, you could use ajax.dataSrc as a function to transfer the structure into a simple array.

    Allan

This discussion has been closed.