Dynamicaly selecting data to display in datatables

Dynamicaly selecting data to display in datatables

KrawcuKrawcu Posts: 3Questions: 0Answers: 0
edited January 2012 in DataTables 1.8
Hello all,
I'm fairly new to datatables but amazed by this great plug-in.

I'm stuck with customization and have no idea how to get further. I've search for solution on forum but couldn't find it.

I would like give the user a possibility to select which data will be displayed in datatables - for example, there are few select lists and each value refers to other data's like name, adress, telephone number etc. By selecting option value, user specifies which data's will be downloaded from MySql database. I've tried to load all records and to filter columns by Colvis plug-in, but this significantly slows down webpage, so the best way is to allow the selection and pass necessary data using ajax. Unfortunately, I'm not jquery expert.

Every help would be appreciated, thank you in advance.

Replies

  • Taylor514ceTaylor514ce Posts: 74Questions: 8Answers: 0
    Hi, I found that searching this forum for "Ajax Source" gave me the information I needed. Your backend application will need to create JSON-formatted data, and other than that, it's just a matter of reloading your data source on the select event of your dropdown.

    This discussion is where I explored the same issue and documented the solution:

    http://datatables.net/forums/discussion/8074/scroll-datatable-to-bottom#Item_6
  • KrawcuKrawcu Posts: 3Questions: 0Answers: 0
    Wow,

    Thank you Taylor514ce, that was fast :)

    Forgive my ignorance, but like i sad i'm not a jquery expert - but still learning.

    If i understood correctly, using the code in link you provided i'll have to replace "sAjaxSource": '/htmlFiles/log.txt', with for example "getdata.php" in which i have to specify a query to database.

    next, for each in select list I will have to set its value param which will correspond to specific column in database. By selecting an option, an ajax code will be called. Is that correct?

    Thank you in advance.
  • Taylor514ceTaylor514ce Posts: 74Questions: 8Answers: 0
    Well, you have to include/define the fnReloadAjax() function in your page. That's actually what loads the data into your table.

    Then, you'll wire the onchange() event of your select list to call that function, passing in the URL to that table in your call. (In my example, I reload by calling SetInterval, to go get new data ever 3.5 seconds.)
  • KrawcuKrawcu Posts: 3Questions: 0Answers: 0
    Thank You Taylor514ce,

    You helped me a lot - now i should figure it out how to deal with my case.

    Once again thank you, million times.
This discussion has been closed.