首先 $aCloumns数组里要有需要查询的列比如说submit_time 这个是按时间跨度查询
array('f'=>'submit_time','d'=>'Reimburse Time','so'=>array('desc','asc'), 'dso'=>'desc','se'=>'btw')
se是搜索‘bwt’是between,具体的在datatable里没有找到
比如说这一列的下标是3 那么在前端页面中会有如下js
$('.show_date').datepicker({dateFormat: 'yy-mm-dd', onSelect: function(){ var st = $('#start_date').val(); var ed = $('#end_date').val(); oReimburseList.fnFilter(st+' 00:00:00'+','+ ed +' 23:59:59', 3); }});
看到实力化的对象是oReimburseList 调用的方法是fnFilter
this.fnFilter = function( sInput, iColumn, bRegex, bSmart, bShowGlobal ) { var oSettings = _fnSettingsFromNode( this[_oExt.iApiIndex] ); if ( !oSettings.oFeatures.bFilter ) { return; } if ( typeof bRegex == 'undefined' ) { bRegex = false; } if ( typeof bSmart == 'undefined' ) { bSmart = true; } if ( typeof bShowGlobal == 'undefined' ) { bShowGlobal = true; } if ( typeof iColumn == "undefined" || iColumn === null ) { /* Global filter */ _fnFilterComplete( oSettings, { "sSearch":sInput, "bRegex": bRegex, "bSmart": bSmart }, 1 ); if ( bShowGlobal && typeof oSettings.aanFeatures.f != 'undefined' ) { var n = oSettings.aanFeatures.f; for ( var i=0, iLen=n.length ; i<iLen ; i++ ) { $('input', n[i]).val( sInput ); } } } else { /* Single column filter */ oSettings.aoPreSearchCols[ iColumn ].sSearch = sInput; oSettings.aoPreSearchCols[ iColumn ].bRegex = bRegex; oSettings.aoPreSearchCols[ iColumn ].bSmart = bSmart; _fnFilterComplete( oSettings, oSettings.oPreviousSearch, 1 ); } };
普通的调用就是select或者单个input 原理一样都要有cloumn在acloumn里然后在前端触发datatable按这个条件去筛选数据
$('#is_paid_filter').change(function(){ oReimburseList.fnFilter( $(this).val(), 7); }); $('#search_box').keyup(function(){ oReimburseList.fnFilter( $(this).val() ); });
还有的是直接通过datatable的sDom生成的具体方法还没研究