Datatable source from json/array
Datatable source from json/array
Hi. Im using javascript array/JSON as source for my datatable. Is possible to use array which contains some unused values? Im not good in english so i try it describe it better.
I have datatable when i wana data like name, surname, age. And in datasource i have name, surname, age, gender, birthdate. Is it possible to build this table, from this array some normal way?
Later i will need some of this data with mRender to create links and etc...
I have datatable when i wana data like name, surname, age. And in datasource i have name, surname, age, gender, birthdate. Is it possible to build this table, from this array some normal way?
Later i will need some of this data with mRender to create links and etc...
This discussion has been closed.
Replies
You can display in the table the fields/columns that you want even if the table has many more fields/column in the db.
Look at this example ans you can have it display the columns that you want and then a popup with all the other fields by pressing the plus key on that line.
http://datatables.net/release-datatables/examples/server_side/row_details.html
Cheers...
i have datatable
[code]
$('#tasks_table').dataTable({
"aaData": tableData,
"aoColumns":[
{"mDataProp": "id"},
{"mDataProp": "nazev"},
{"mDataProp": "test"},
{"mDataProp": "zakaznik"},
{"mDataProp": "konec.date"},
{"mDataProp": "id"},
{"mDataProp": "id"},
{"mDataProp": "id"},
{"mDataProp": "id"},
{"mDataProp": "id"},
{"mDataProp": "id"},
{"mDataProp": "id"},
{"mDataProp": "id"}
]
});
[/code]
And array looks like
[code]
var tableData = [{"id":100,"id_projektu":8,"nazev":"test","zakaznik":"","platforma":"","brzda":"","log":"","popis":"","zacatek":{"date":"2012-11-26 00:00:00","timezone_type":3,"timezone":"Europe\/Prague"},"konec":{"date":"2012-11-26 00:00:00","timezone_type":3,"timezone":"Europe\/Prague"},"smazano":"0","priorita":"0","hotovo":"1","id_predka":null,"zadal":1,"level":0,"nazevProjektu":"test","jmeno":null,"prijmeni":null,"idUzivatele":null,"nazevPredka":null},
{"id":1517,"id_projektu":8,"nazev":"test gantt color","zakaznik":"","platforma":"","brzda":"","log":"","popis":"","zacatek":{"date":"2012-11-26 00:00:00","timezone_type":3,"timezone":"Europe\/Prague"},"konec":{"date":"2013-03-20 00:00:00","timezone_type":3,"timezone":"Europe\/Prague"},"smazano":"0","priorita":"0","hotovo":"0","id_predka":null,"zadal":1,"level":0,"nazevProjektu":"test","jmeno":"Karel","prijmeni":"Kozelka","idUzivatele":1,"nazevPredka":null},
{"id":1530,"id_projektu":4,"nazev":"dfgdfg","zakaznik":"asf56a4sd","platforma":"as5d6a4s","brzda":"as6d54","log":"","popis":"","zacatek":{"date":"2012-09-26 00:00:00","timezone_type":3,"timezone":"Europe\/Prague"},"konec":{"date":"2012-09-26 00:00:00","timezone_type":3,"timezone":"Europe\/Prague"},"smazano":"0","priorita":"56","hotovo":"0","id_predka":null,"zadal":1,"level":0,"nazevProjektu":"sgsdf56s4","jmeno":"Karel","prijmeni":"Kozelka","idUzivatele":1,"nazevPredka":null},
{"id":1531,"id_projektu":3,"nazev":"asdas","zakaznik":"asd5165","platforma":"asd56as1d","brzda":"asd65a1sd","log":"http:\/\/jabcz-vyv-epbsr:1000\/","popis":"","zacatek":{"date":"2012-09-20 00:00:00","timezone_type":3,"timezone":"Europe\/Prague"},"konec":{"date":"2012-09-26 00:00:00","timezone_type":3,"timezone":"Europe\/Prague"},"smazano":"0","priorita":"45","hotovo":"0","id_predka":null,"zadal":1,"level":0,"nazevProjektu":"ID651651","jmeno":"Karel","prijmeni":"Kozelka","idUzivatele":1,"nazevPredka":null},
{"id":1518,"id_projektu":8,"nazev":"asd","zakaznik":"","platforma":"","brzda":"","log":"","popis":"","zacatek":{"date":"2013-03-14 00:00:00","timezone_type":3,"timezone":"Europe\/Prague"},"konec":{"date":"2013-03-30 00:00:00","timezone_type":3,"timezone":"Europe\/Prague"},"smazano":"0","priorita":"0","hotovo":"0","id_predka":1517,"zadal":1,"level":1,"nazevProjektu":"test","jmeno":null,"prijmeni":null,"idUzivatele":null,"nazevPredka":"test gantt color"},
{"id":1525,"id_projektu":8,"nazev":"task 01","zakaznik":"","platforma":"","brzda":"","log":"","popis":"","zacatek":{"date":"2013-05-10 00:00:00","timezone_type":3,"timezone":"Europe\/Prague"},"konec":{"date":"2013-05-17 00:00:00","timezone_type":3,"timezone":"Europe\/Prague"},"smazano":"0","priorita":"0","hotovo":"0","id_predka":100,"zadal":1,"level":1,"nazevProjektu":"test","jmeno":"Karel","prijmeni":"Kozelka","idUzivatele":1,"nazevPredka":"test"},
{"id":1526,"id_projektu":8,"nazev":"task 02","zakaznik":"","platforma":"","brzda":"","log":"","popis":"","zacatek":{"date":"2013-05-08 00:00:00","timezone_type":3,"timezone":"Europe\/Prague"},"konec":{"date":"2013-05-31 00:00:00","timezone_type":3,"timezone":"Europe\/Prague"},"smazano":"0","priorita":"0","hotovo":"1","id_predka":100,"zadal":1,"level":1,"nazevProjektu":"test","jmeno":null,"prijmeni":null,"idUzivatele":null,"nazevPredka":"test"},
{"id":1527,"id_projektu":8,"nazev":"task 03","zakaznik":"","platforma":"","brzda":"","log":"","popis":"","zacatek":{"date":"2013-05-06 00:00:00","timezone_type":3,"timezone":"Europe\/Prague"},"konec":{"date":"2013-05-08 00:00:00","timezone_type":3,"timezone":"Europe\/Prague"},"smazano":"0","priorita":"0","hotovo":"0","id_predka":100,"zadal":1,"level":1,"nazevProjektu":"test","jmeno":null,"prijmeni":null,"idUzivatele":null,"nazevPredka":"test"},
{"id":1528,"id_projektu":8,"nazev":"task 04","zakaznik":"","platforma":"","brzda":"","log":"","popis":"","zacatek":{"date":"2013-05-09 00:00:00","timezone_type":3,"timezone":"Europe\/Prague"},"konec":{"date":"2013-07-26 00:00:00","timezone_type":3,"timezone":"Europe\/Prague"},"smazano":"0","priorita":"0","hotovo":"0","id_predka":100,"zadal":1,"level":1,"nazevProjektu":"test","jmeno":null,"prijmeni":null,"idUzivatele":null,"nazevPredka":"test"},
{"id":1529,"id_projektu":8,"nazev":"subtask 21","zakaznik":"","platforma":"","brzda":"","log":"","popis":"","zacatek":{"date":"2013-05-11 00:00:00","timezone_type":3,"timezone":"Europe\/Prague"},"konec":{"date":"2013-05-14 00:00:00","timezone_type":3,"timezone":"Europe\/Prague"},"smazano":"0","priorita":"0","hotovo":"0","id_predka":1526,"zadal":1,"level":2,"nazevProjektu":"test","jmeno":null,"prijmeni":null,"idUzivatele":null,"nazevPredka":"task 02"}];
[/code]
Data draw in table nice, but still get that anoying "DataTables warning (table id='tasks_table'): Requested unknown parameter 'test' from data source for row 0"
I almost ate my keyboard :(
thanks