2014-10-19 50 views
0

我遇到了問題數據表1.10通過輸入元素進行列篩選。DataTable 1.10x jQuery列篩選器通過輸入文本框服務器端

jQuery(document).ready(function() {  

    dt_table = $('#datatable_list').DataTable({ 
     "dom": "<'top'i>rt<'table-scrollable't>lp", 
     "processing": true, 
     "serverSide": true, 
     "ajax": "ajax/list_json.php", 
     "pageLength": 10, 
     "autoWidth": false 
    }); 

    $('#quickfind').on('keyup', function() { dt_table.search(this.value).draw(); }); 

}); 

正如你可以看到我使用服務器端處理與JSON輸出。總榜單填補不錯。

在表中存在與4個輸入頁腳:

       <tfoot> 
            <tr> 
             <th><input type="text" id="filters_0" name="filters_0" class="form-control form-filter"></th> 
             <th><input type="text" id="filters_1" name="filters_1" class="form-control form-filter"></th> 
             <th><input type="text" id="filters_2" name="filters_2" class="form-control form-filter"></th> 
             <th><input type="text" id="filters_3" name="filters_3" class="form-control form-filter"></th> 
            </tr> 
           </tfoot> 

我使用的標準ssp.class.php類。請使用這個簡單的列過濾項目工作4天。

我想要的很簡單。快速查找文本框非常適合搜索整個表格。但我想過濾每列。像'filters_0'是產品的ID。但這是行不通的。

請您理解我使用最新的DataTabes 1.10。

回答

1

在將它們作爲搜索數據傳遞之前,您首先必須序列化您的字段(在tfoot中)。 我使用一個外部表,並提交時,只要做到這一點:

dt_table = $('#datatable_list'); 
var formData = $('#search-form-orders').serialize(); 
dt_table.search(formData).draw(); 

然後在服務器端,我不使用SSP而是一個定製的框架,所以:

// get the 'search' array from $_GET and don't forget to clean it !!! 
if($search['value'] !=='') 
    foreach (explode('&', $search['value']) as $chunk) { 
     $param = explode("=", $chunk); 
     $field = urldecode($param[0]); 
     $value = urldecode($param[1]); 
     $criterias[] = array($field => $value); 
    } 

最後治療制定要求的標準

相關問題