how to display data table headers dynamically based on return data?

how to display data table headers dynamically based on return data?

dinesh_thapa07dinesh_thapa07 Posts: 9Questions: 2Answers: 0

i have search.jsp with three drop down elements where user can select their values and click search button. after this, result set will display in data table and i am using spring 4, jsp, jstl, jquery and javascript. if data table headers are constant everytime user clicks search then it would not be problem for me but here headers of data table depends on user and his search criteria. result set could be 20, 30, 40, or 5 rows and depending on these resultset i have to determine the Headers for the data table and i have no idea how could i achieve this since i am new to Data table API. Please help me

Answers

  • john_ljohn_l Posts: 45Questions: 0Answers: 12

    How are you getting the result set to the browser? If you're doing it in an AJAX call, then you can always return additional data (though you might need to do your own AJAX call before initializing the table, rather than relying on the built in AJAX functionality in Datatables).

    In some of my apps, I use this method to return along with the data for the rows, a list of column objects, which I pass into the datatable initialization as aoColumns, and the sorting definitions for the columns that I pass in as aaSorting.

  • dinesh_thapa07dinesh_thapa07 Posts: 9Questions: 2Answers: 0

    hi john, Thank you for answering. i am using Data table in built Ajax call to get data to the browser right now. so r you suggesting me to do own AJax call to get all the require data and then pass it to Data table even like custom headers ?

  • john_ljohn_l Posts: 45Questions: 0Answers: 12

    Yes, that's that I mean - make a web service call to pull down all the data you need for the table, including header definitions as well as the data rows, and then initialize the datatable from the success callback of the ajax call.

This discussion has been closed.