Getting native json data from api
Getting native json data from api
AMKDP
Posts: 2Questions: 1Answers: 0
Hello.
Consider I have this for datatable initialization:
listDataTable = $('#MembersTable').dataTable({
"serverSide": true,
"initComplete": initComplete,
"ajax": {
"url": "/Circular/JdtGetJson",
"type": "POST"
},
"columns": [
{
"name": "Title",
"data": "Title",
"title": "Title",
"individualColumnInfo": {
"filterMode": 1,
"useRemoteData": false,
"filterList": ["94", "93"]
}
},
{
"name": "Action",
"data": "Action",
"orderable": false,
"searchable": false,
"title": "Actions",
"width": "100px",
"render": _dataTablesActionTemplate
}],
});
Now I want to iterate over all columns in my table using api() :
listDataTable.api().columns().every(function (colIndx) {
var that = this;
//var individualColumnInfo = ????? this.column(1).individualColumnInfo ?????
});
I want to access individualColumnInfo in my source json.
How can I do this? Is it possible throgh api()?
Thank you.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You could use
api().settings()[0].aoColumns[ colIndx ].individualColumnInfo
.That will work and will continue to work, but I would urge caution when using
settings()
. The properties in the settings object are considered to be private (e.g.aoColumns
). They can, will and do change between releases. That one is unlikely to change in fairness, but we need to be careful.Having said that there is no public API to access properties like you want...
Allan
Thank You for the answer.
I've used dataTable.fnSettings().aoColumns[colIndx].individualColumnInfo
I think your's is better.
"there is no public API to access properties like you want" but why? I needed this, because I working on an lightweight - model bound datatables library on ASP.net MVC, and I was faced this problem when I wanted to write some -Individual column filtering- to provide a mechanism to users to have specific column filter or anything else on individual columns in their view-model, like this:
And its get rendered on view this way:
I can rewrite this, and make JdtIndividualColumnFiltererInitializer to depend on JqueryDataTables which was parent object of it, but I think it may become so complicated to users to understand on first practices.
I think its better to you to keep this way or provide a reliable api to access source json which sent by server for each column.
Thank you
Because it hasn't really been needed until now. I don't plan to change the method you have used - it will keep working with the 1.x releases of DataTables, and in all likelihood v2.x as well.
It is something that will be useful - I can see that, and I will add it in future, but it doesn't exist yet (other than using the method you have used).
Allan