In JQuery Datatables plugin, how do we attach JSON to a Datatable-enabled table when
- there are some columns in Datatable-enabled table that are not in JSON
- there are some columns that are in JSON, but we don’t want to show it in the Datatable-enabled table
Example for #1
table columns
person_id, first_name, last_name, age
JSON
{{'person_id' : 1, 'first_name' : 'John', 'last_name' : 'Doe'}, ....}
Example for #2
table columns
product_id, manufacturer_name
JSON
{{'product_id' : 1, 'manufacturer_name' : 'Product X', 'manufacturer_code' : '144ctow4'}, ....}
DataTables accepts only
<table>contents or javascript arrays. JSON must be instantiated and converted from an object into an appropriate array. If you have two data sources they must be combined before instantiating the DataTable with the appropriate information.1)If you provide some context for your “there are some columns in Datatable-enabled table that are not in JSON” I can recommend some javascript to mesh the new data.
2)Are those strings you have posted representative of your “JSON”, if so I don’t believe it is well-formed. A comma-delimited set of sub-object would be an array, eg:
[{‘person_id’ : 1, ‘first_name’ : ‘John’, ‘last_name’ : ‘Doe’}, ….]
EDIT: Regarding the information added in the comment, to handle CRUD operations like delete you can use the techniques outlined on the DataTables blog.