doucaigai7176 2012-07-24 16:41
浏览 57
已采纳

如何动态填充DataTables选择菜单?

I've a DataTables table that displays information from a MySQL database. I'm trying to create drop-down filters, <select>, like the ones used here. I know that the server-side tables can't use that precise example, but I'm not sure how to change it to make it work with a server-side database table.

How would I create drop-down menus, populated with information from the table/database, to filter a DataTables table?

EDIT: The server side is in PHP. I tried to query the database and create a separate menu with PHP and send the JSON-encoded information into select menus.

  • 写回答

2条回答 默认 最新

  • duan3019 2012-07-24 17:25
    关注

    Ok I don't know the specifics on how to achieve this with PHP ( I know it is most definitely possible) so I'll give you a generic rundown.You can ask me for specific details later and I'll edit my answer.

    First you have to have the ajax source.

    You can then use the same function ( from serverside ) to dynamically populate the options in your dropdowns. This is how

    1st you make the html code for empty <select id='id1'></select> Then you can use the draw event from datatables on which you can make an ajax request to populate the dropdowns $(oTable).on("draw", function() { ... });. After that you can refresh the table and the dropdowns when one of the select option changes.

    This is the most generic way of answering your (vague) question.

    Here are some more resources:

    Refresh ajax data: how can I trigger jquery datatables fnServerData to update a table via AJAX when I click a button?

    Let me know if you have more specific questions.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?