如何在页脚中添加搜索到DataTable的某些列?

时间:2016-03-06 00:54:37

标签: javascript html dom javascript-events datatables

我需要将不同类型(文本框,下拉列表)的过滤添加到DataTable中的某些(!)单个列到页脚。也就是说,我希望能够通过单个列搜索我添加到页脚的每个过滤器,并且过滤器的类型将取决于列,例如,对于列0,它是文本框,对于列1它是下拉列表,对于第5列,它是一个日期选择器。

这是一个测试示例。注意构造函数的新类型(DataTable,而不是dataTable)。

$("#my-table").DataTable({
  //.....
  , 'initComplete': function (settings, json) {
      var cl = this.api().columns(1); //2nd column

      $(cl.footer()).html("fdsfds"); //doesn't work

      //this.api().columns().every(function(){
        //var column = this;
        //$(column.footer()).html('fdsfsdfd');  //doesn't work either
      //});


      //neither this

      //var api = this.api();
      // $(api.column(1).footer()).html('dsfs2222');
  });

问题是什么?

1 个答案:

答案 0 :(得分:1)

你需要在这里做两件事。

  • 在桌面上添加一个tfoot以便它有一个空间来添加它
[Thread-2] ERROR heros.solver.CountingThreadPoolExecutor - Worker
 thread execution failed: null java.lang.NullPointerException   at
 soot.toolkits.graph.UnitGraph.<init    (UnitGraph.java:76)   at
 soot.toolkits.graph.ExceptionalUnitGraph.<init    (ExceptionalUnitGraph.java:158)
   at
 soot.jimple.toolkits.scalar.UnreachableCodeEliminator.internalTransform(UnreachableCodeEliminator.java:79)
   at soot.BodyTransformer.transform(BodyTransformer.java:51)  at
 soot.Transform.apply(Transform.java:105)  at
 soot.JimpleBodyPack.applyPhaseOptions(JimpleBodyPack.java:61)     at
 soot.JimpleBodyPack.internalApply(JimpleBodyPack.java:95)     at
 soot.Pack.apply(Pack.java:125)    at
 soot.jimple.JimpleMethodSource.getBody(JimpleMethodSource.java:49)    at
 soot.SootMethod.getBodyFromMethodSource(SootMethod.java:91)   at
 soot.SootMethod.retrieveActiveBody(SootMethod.java:322)   at
 soot.PackManager$3.run(PackManager.java:1223)     at
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
   at
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
   at java.lang.Thread.run(Thread.java:745)
 java.util.concurrent.RejectedExecutionException: Task
 soot.PackManager$3@2e5e3fd3 rejected from
 heros.solver.CountingThreadPoolExecutor@2db04d6d[Shutting down, pool
 size = 3, active threads = 3, queued tasks = 0, completed tasks = 3]
   at
 java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2048)
   at
 java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:821)
   at
 java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1372)
   at
 heros.solver.CountingThreadPoolExecutor.execute(CountingThreadPoolExecutor.java:51)
   at soot.PackManager.retrieveAllBodies(PackManager.java:1219)    at
 soot.PackManager.runPacksNormally(PackManager.java:463)   at
 soot.PackManager.runPacks(PackManager.java:396)   at
 soot.Main.run(Main.java:271)  at soot.Main.main(Main.java:147)
  • 使用像此处指定的footerCallBack http://datatables.net/examples/advanced_init/footer_callback.html您还使用了列而不是列。

     <table id="example" class="display" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th>First name</th>
                    <th>Last name</th>
                    <th>Position</th>
                    <th>Office</th>
                    <th>Salary</th>
                </tr>
            </thead>
            <tfoot>
                <tr>
                    <th colspan="4" style="text-align:right">Total:</th>
                    <th></th>
                </tr>
            </tfoot>
            <tbody>
                <tr>
                    <td>Tiger</td>
                    <td>Nixon</td>
                    <td>System Architect</td>
                    <td>Edinburgh</td>
                    <td>$320,800</td>
                </tr>
            </tbody>
    </table>