我第一次实现数据表插件,显然是在stackoverflow成员的帮助下。再次感谢他们。现在我关心的问题如下: 我有一个页面,其中包含一些搜索字段,例如名称文本字段,用户名文本字段,类别下拉列表,年龄范围等,以及一个提交按钮进行搜索。默认情况下,将显示所有记录,并且通过使用数据表,我可以按升序或降序对它们进行排序。我仅通过 css 删除插件的默认搜索字段(显示:无(。现在,当我通过该搜索表单搜索记录时,我的记录列表应该使用该数据表插件实现。但我做不到。请帮我如何处理。自定义搜索如下所示:
<form name="search_user_form" id="search_user_form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET" >
<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" class="form_table" id="searching_parameter" >
<tr>
<td>Name : <input type="text" class="textbox_small" name="search_name" id="search_name" value="<?php echo $_REQUEST['search_name']; ?>" /></td>
<td>Username : <input type="text" class="textbox_small" name="search_username" id="search_username" value="<?php echo $_REQUEST['search_username']; ?>" /></td>
</tr>
<tr>
<td>Email : <input type="text" class="textbox_small" name="search_email" id="search_email" value="<?php echo $_REQUEST['search_email']; ?>" /></td>
<td>Age : <!--<input type="text" class="textbox_small" name="search_age" id="search_age" value="<?php echo $_REQUEST['search_age']; ?>" />-->
<input type="text" size="3" value="<?php echo $_REQUEST['min_age']; ?>" name="min_age" id="min_age" maxlength="2" onKeyPress="return numbersonly(event, false)" >
To <input type="text" size="3" value="<?php echo $_REQUEST['max_age']; ?>" name="max_age" id="max_age" maxlength="2" onKeyPress="return numbersonly(event, false)" >
</td>
</tr>
<tr>
<td colspan="2">Privilege:
<select class="soring_select" name="search_privilege" id="search_privilege" style="height:28px;">
<option value="0" <?php echo $selection_agent;?>>Agent</option>
<option value="1" <?php echo $selected_admin;?>>Admin</option>
<option value="2" <?php echo $selected_supeadmin;?>>Superadmin</option>
<option value="3" <?php echo $selected_owner;?>>Owner</option>
<option value="all" <?php echo $selected_no;?>>All Privilege</option>
</select>
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="search_user_btn" id="search_user_btn" value="Search"> <input type="reset" value="Cancel" /></td>
</tr>
</table>
</form>
对于插件:
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "datatabledb.php?query=<?php (isset($_REQUEST['search_user_btn']))?$search_sql:'';?>",
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"aButtons": [
{
"sExtends": "csv",
"sButtonText": "Save to CSV"
}
]
}
} );
您可以从数据表开始 多重过滤器 但是,您应该在按下提交按钮后以键/值对的形式传递数据:
http://datatables.net/plug-ins/api#fnMultiFilter
您可以通过以下方式调用它:
var defaultFilter = {"name":"john","username":"userjohn"};
oTable.fnMultiFilter(defaultFilter);
对于范围,您应该做一些事情来在 API 中进行更改。