【问题标题】:datatable jquery plugin: populate select to filter data acquired through ajaxdatatable jquery插件:填充select过滤通过ajax获取的数据
【发布时间】:2014-05-21 02:30:38
【问题描述】:

我正在使用强大的 jQuery 插件 dataTable,我需要: 1.从ajax源获取数据 2. 添加选择过滤输出

这是 HTML 代码:

<table id='probecardlist' class='display' cellspacing='0' width='100%'>
<thead>
    <tr>
        <th>Selection</th>
        <th>Id</th>
        <th>Production Area</th>
        <th>Format</th>
        <th>Orientation</th>
        <th>Parallelism</th>
    </tr>
</thead><thead>
    <tr>
        <th></th>
        <th></th>
        <th><select id='filter.productionarea'></select></th>
        <th><select id='filter.format'></select></th>
        <th><select id='filter.orientation'></select></th>
        <th></th>
    </tr>
</thead>
</table>

这就是 JS:

$( document ).ready(function() {
var table = $( '#probecardlist' ).dataTable({
    'ajax' : 'http://whaelse.url/query.php',
    'paging' : false,
    'searching' : false,
    'ordering' : true,
    'columns' : [
        { 'data' : 'selection' },
        { 'data' : 'id' },
        { 'data' : 'productionarea' },
        { 'data' : 'format' },
        { 'data' : 'orientation' },
        { 'data' : 'dicecount' }
    ],
    'fnInitComplete' : function( oSettings , json ) {
        console.log( this.column( 'format:name' ).data() );
             })
})
});

当我尝试仅列出(在控制台上)“格式”列的值列表时,我收到这样的错误:

Object #HTMLTableElement 没有方法'column'。

嗯……怎么了?

【问题讨论】:

    标签: javascript jquery ajax datatables


    【解决方案1】:

    'fnInitComplete'实现了[this.api()]方法来获取对象的属性

    'fnInitComplete' : function ( oSettings , json ) {
         var api = this.api();
         api.column ( 'format:name' ).data().unique().sort().each( function ( v ) {
            console.log (v);
         });
      }
    

    【讨论】:

      猜你喜欢
      • 2012-08-16
      • 2016-04-20
      • 1970-01-01
      • 2012-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-29
      • 2021-09-27
      相关资源
      最近更新 更多