datatables dynamic columns from array of objects
datatables dynamic columns from array of objects
mrwillow
Posts: 1Questions: 0Answers: 0
Hello , i have bit problem to show data in a datatable when I received data from ajax, I receive the next object from the server:
{
"aaData": [
{
"media": {
"url": "/file/532caafbf20aac2f5207587d/",
"type": "image",
"thumbnail": "",
"thumbnail_size": [],
"image_size": []
},
"vote_type": "dislike",
"name": "blasdas",
"visits": 0,
"attributes": [
{
"fields": {
"allowed_hosts": [],
"required": true,
"id": "5328ab63f20aac3ac4ea01e7",
"name": "links",
"class": "url"
},
"schema": {
"provider_url": "url",
"description": "string",
"title": "string",
"url": "url",
"thumbnail_width": "int",
"thumbnail_url": "string",
"version": "string",
"provider_name": "string",
"type": "string",
"thumbnail_height": "int"
}
},
{
"fields": {
"required": false,
"id": "5328ab63f20aac3ac4ea01e8",
"name": "barras",
"class": "progress"
},
"schema": {
"percent": "decimal"
}
},
{
"fields": {
"required": true,
"id": "5328ab63f20aac3ac4ea01e9",
"name": "ciudad",
"class": "location"
},
"schema": {
"latitude": "decimal",
"name": "string",
"longitude": "decimal"
}
}
]
}
]
}
in this object i have a property calls attributes, this property is an objects array, i want to add this attributes in columns to my datatable
how can I do that?
I have this config in my datatable
var oTable = $('#tableAssets').dataTable( {
"bProcessing": true,
"bServerSide": false,
"sScrollX": "100%",
"sScrollXInner": "100%",
"bScrollCollapse": true,
"oColReorder": {
"iFixedColumns": 2
},
"sDom": 'CR<"clear">lfrtip',
"oColVis": {
"buttonText": "Show Attributes",
"aiExclude": [0,1]
},
"sAjaxSource": "../../../collections/"+this.options._id+"/assets/?data=true",
"aoColumns": [
{ "sTitle": "Media", "mData": "media.thumbnail" },
{ "sTitle": "Name", "mData": "name" },
{ "sTitle": "url", "mData": "attributes.0.fields.class" },
{ "sTitle": "progress", "mData": "attributes.1.fields.class"},
{ "sTitle": "location", "mData": "attributes.2.fields.class"},
],
"bRetrieve" : true,
} );
In the attribute aoColumns i want the last three objects dynamic i want to use the data from the object that server response
Please I need a really help with this beacause i'm Breaking my head with that litle problem
{
"aaData": [
{
"media": {
"url": "/file/532caafbf20aac2f5207587d/",
"type": "image",
"thumbnail": "",
"thumbnail_size": [],
"image_size": []
},
"vote_type": "dislike",
"name": "blasdas",
"visits": 0,
"attributes": [
{
"fields": {
"allowed_hosts": [],
"required": true,
"id": "5328ab63f20aac3ac4ea01e7",
"name": "links",
"class": "url"
},
"schema": {
"provider_url": "url",
"description": "string",
"title": "string",
"url": "url",
"thumbnail_width": "int",
"thumbnail_url": "string",
"version": "string",
"provider_name": "string",
"type": "string",
"thumbnail_height": "int"
}
},
{
"fields": {
"required": false,
"id": "5328ab63f20aac3ac4ea01e8",
"name": "barras",
"class": "progress"
},
"schema": {
"percent": "decimal"
}
},
{
"fields": {
"required": true,
"id": "5328ab63f20aac3ac4ea01e9",
"name": "ciudad",
"class": "location"
},
"schema": {
"latitude": "decimal",
"name": "string",
"longitude": "decimal"
}
}
]
}
]
}
in this object i have a property calls attributes, this property is an objects array, i want to add this attributes in columns to my datatable
how can I do that?
I have this config in my datatable
var oTable = $('#tableAssets').dataTable( {
"bProcessing": true,
"bServerSide": false,
"sScrollX": "100%",
"sScrollXInner": "100%",
"bScrollCollapse": true,
"oColReorder": {
"iFixedColumns": 2
},
"sDom": 'CR<"clear">lfrtip',
"oColVis": {
"buttonText": "Show Attributes",
"aiExclude": [0,1]
},
"sAjaxSource": "../../../collections/"+this.options._id+"/assets/?data=true",
"aoColumns": [
{ "sTitle": "Media", "mData": "media.thumbnail" },
{ "sTitle": "Name", "mData": "name" },
{ "sTitle": "url", "mData": "attributes.0.fields.class" },
{ "sTitle": "progress", "mData": "attributes.1.fields.class"},
{ "sTitle": "location", "mData": "attributes.2.fields.class"},
],
"bRetrieve" : true,
} );
In the attribute aoColumns i want the last three objects dynamic i want to use the data from the object that server response
Please I need a really help with this beacause i'm Breaking my head with that litle problem
This discussion has been closed.