[英]datatable jquery plugin: populate select to filter data acquired through ajax
我使用的是功能强大的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() );
})
})
});
当我尝试仅列出(在控制台上)“格式”列的值列表时,出现以下错误:
对象#HTMLTableElement没有方法'column'。
嗯...怎么了?
“ fnInitComplete”实现[this.api()]方法以获取对象的属性
'fnInitComplete' : function ( oSettings , json ) {
var api = this.api();
api.column ( 'format:name' ).data().unique().sort().each( function ( v ) {
console.log (v);
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.