Integrate nedb with datatables

Integrate nedb with datatables

lowzerboydlowzerboyd Posts: 2Questions: 1Answers: 0

Hey guys, i'm trying to use datatable with nedb in my electron application, but not sure how to retrieve data from nedb and pass as data source in datatables. Here is what i got :

Nedb query script :

db.find({}, function (err, docs) {
});

My Datatable:
myTable = $('#example').DataTable({
ajax: {
// I think i should put here the nedb querying
},
})

Nedb generetes a filename.json, here is how the data looks like in the file

{"a":5,"b":3}
{"a":7,"b":23}
{"a":5,"b":10}

Does anyone can helpe me with this integration?

Answers

  • kthorngrenkthorngren Posts: 21,174Questions: 26Answers: 4,923

    basically your server script needs to return a JSON string with the rows in an array as described in the Ajax docs. Looking something like this:

    {
      "data":
        [
          {"a":5,"b":3},
          {"a":7,"b":23},
          {"a":5,"b":10}
        ]
    }
    

    Then use columns.data to define the columns, for example:

    columns:  [
      { data: "a" },
      { data: "b" },
    ]
    

    Kevin

  • lowzerboydlowzerboyd Posts: 2Questions: 1Answers: 0

    Hi Ktrorngre, thanks for your answer. The nedb docs says that query returns an array. But query function is async. I would like to know how can i query the data and then pass to my datatable

  • kthorngrenkthorngren Posts: 21,174Questions: 26Answers: 4,923

    Use the ajax option with a URL to your server script that runs your dedb query. I'm not familiar with nedb and the specifics of how you program your server script is up to the language you are using. Datatables doesn't care about what your server script does as long as you return the data in the format it requires.

    Kevin

This discussion has been closed.