How to change the aaData source dynamically

How to change the aaData source dynamically

amey1309amey1309 Posts: 28Questions: 0Answers: 0
edited November 2013 in General
Hello,
Am getting my table data as [code] ""aaData":<?php echo json_encode($purchases); ?>,"[/code] . It works great.
Now I want to change the content of Datatable on selection of an option from Select Box(warehouse1(Default)/warehouse2) and generate the table based on the data fetched from sql table(warehouse1/warehouse2/warehouse3) as selected options without refreshing the page.
So how do I do it?? Is it fnReloadAjax or something else ?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Use the fnClearTable and fnAddData API methods.

    Allan
  • amey1309amey1309 Posts: 28Questions: 0Answers: 0
    edited November 2013
    Hello Allan,
    I have used it but don't know how to assign a javascript fuction to fnAddData.Suppose i have a function "get_records()" which gets JSON data, then how do I assign it to API.
    [code]$('#example').dataTable().fnAddData(get_records() );[/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    That looks fine to me as long as get_records is returning an array. Is it?

    Allan
  • amey1309amey1309 Posts: 28Questions: 0Answers: 0
    edited November 2013
    Hello Allan,
    It working fine but the problem is that am using select boxes on every column as filter.But the options in those select boxes are from previous data .[quote] oTable.fnClearTable();[/quote] doesn't clears the options and doesn't fills it with new data which is fetched using [quote]fnAddData[/quote].So what do I have to do to referesh those??

    Thanks
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    You mean you have select inputs in the footer? DataTables knows nothing about them, so you'd need to clear them out and reset their values using whatever method you used to put them there initially.

    Allan
  • amey1309amey1309 Posts: 28Questions: 0Answers: 0
    Hello Allan,
    Thanks a lot for the help.I recalled the method.I thought there would be an efficient method then this so I asked you.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I'll get around to writing a fully integrated filtering plug-in at some point! I've got a prototype already, but still needs a lot of work. Next year :-)

    Allan
  • amey1309amey1309 Posts: 28Questions: 0Answers: 0
    That would be great ALLAN !!! :-))
This discussion has been closed.