How can I load table column headings and data from server using ajax ?
How can I load table column headings and data from server using ajax ?
Hi There,
I have a requirement where a user has an option to select a set of columns (say 3 columns out of 10 available columns) and when click of a button, the table should load data for those selected 3 columns and their table column headings from the the server, using Ajax. I'm using columnDef for this and having json as below -
{"aaData":[],"aoColumnDefs":[{"aTargets":"0","mDataProp":"projectName","sTitle":"Project Name","bVisible":true,"bSearchable":true},{"aTargets":"1","mDataProp":"projectStatus","sTitle":"Project Status","bVisible":true,"bSearchable":true}],"data":[{"projectName":"Test Project 3","projectStatus":"No Status","projectUrl":null,"projectId":"4"},{"projectName":"Test Project 12","projectStatus":"On Track","projectUrl":null,"projectId":"8"},{"projectName":"Test Project 5","projectStatus":"Minor Impact","projectUrl":null,"projectId":"7"},{"projectName":"Test Project 1","projectStatus":null,"projectUrl":null,"projectId":"2"},{"projectName":"Test Project 4","projectStatus":"Minor Impact","ccDate":null,"projectUrl":null,"projectId":"5"},{"projectName":"Test Project 2","projectStatus":"No Status","projectUrl":null,"projectId":"3"}]}
I'm trying with some options here but I couldn't succeed. Have anyone tried it before or Is this possible to load the column headings from the server over ajax ?
Many thanks for your time and help here. Any sample code will be much appreciated.
Thanks
Answers
Is ColVis what you want? http://www.datatables.net/extensions/colvis/
@travelerjjm Thank you for your response. I tried using this plugin and my requirement is sort of complicated in the sense that, the table should display columns as user selected and the user has option to choose in which order the columns has to display in the table. During the early phase of development, I used a simple javascript function to turn on / off the column visible option on the table, but later when the other features (such as give user option to sort and the table should auto apply columnfilter on each added column) added, the performance sucked (browser hangs all the time). So, I decided to have the server send data in the user selected columns & order, so that it will be a simple ajax load of data with col headings to minimize load on the browser. I have 34 columns ( I know it sounds strange but have to deal with this) and user can chose all or a couple from this list.
I'm using the below plugins for my requirments and appreciate if you can shed any light on how effectively this can be done -
dataTables.colReorder.js
dataTables.tableTools.min.js
jquery.dataTables.columnFilter.js
Many thanks for your time and your comments here.
Ok.. I made it to work this way. For some reason, I think there is another way using datatables inbuilt ajax function to do the same as am doing here..
Hope it helps somebody..!!