easyUI datagrid表格列表添加多搜索条件框

 Add search functionality in DataGrid

In this tutorial we will show you how to get data from database and display them to datagrid. And then demonstrate how to search through the results according the search terms the user enters.

Create DataGrid

Create the datagrid with paging feature and then add a toolbar to it.

  1. <table id="tt" class="easyui-datagrid" style="width:600px;height:250px"  
  2.         url="datagrid24_getdata.php" toolbar="#tb"  
  3.         title="Load Data" iconCls="icon-save"  
  4.         rownumbers="true" pagination="true">  
  5.     <thead>  
  6.         <tr>  
  7.             <th field="itemid" width="80">Item ID</th>  
  8.             <th field="productid" width="80">Product ID</th>  
  9.             <th field="listprice" width="80" align="right">List Price</th>  
  10.             <th field="unitcost" width="80" align="right">Unit Cost</th>  
  11.             <th field="attr1" width="150">Attribute</th>  
  12.             <th field="status" width="60" align="center">Stauts</th>  
  13.         </tr>  
  14.     </thead>  
  15. </table>  

The toolbar is defined as:

  1. <div id="tb" style="padding:3px">  
  2.     <span>Item ID:</span>  
  3.     <input id="itemid" style="line-height:26px;border:1px solid #ccc">  
  4.     <span>Product ID:</span>  
  5.     <input id="productid" style="line-height:26px;border:1px solid #ccc">  
  6.     <a href="#" class="easyui-linkbutton" plain="true" onclick="doSearch()">Search</a>  
  7. </div>  

When user enters search values and press search button, the 'doSearch' function will be called:

  1. function doSearch(){  
  2.     $('#tt').datagrid('load',{  
  3.         itemid: $('#itemid').val(),  
  4.         productid: $('#productid').val()  
  5.     });  
  6. }  

The code above we call 'load' method to load new datagrid data. We need to pass 'itemid' and 'productid' parameters to server.

The Server Code
  1. include 'conn.php';  
  2.   
  3. $page = isset($_POST['page']) ? intval($_POST['page']) : 1;  
  4. $rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;  
  5. $itemid = isset($_POST['itemid']) ? mysql_real_escape_string($_POST['itemid']) : '';  
  6. $productid = isset($_POST['productid']) ? mysql_real_escape_string($_POST['productid']) : '';  
  7.   
  8. $offset = ($page-1)*$rows;  
  9.   
  10. $result = array();  
  11.   
  12. $where = "itemid like '$itemid%' and productid like '$productid%'";  
  13. $rs = mysql_query("select count(*) from item where " . $where);  
  14. $row = mysql_fetch_row($rs);  
  15. $result["total"] = $row[0];  
  16.   
  17. $rs = mysql_query("select * from item where " . $where . " limit $offset,$rows");  
  18.   
  19. $items = array();  
  20. while($row = mysql_fetch_object($rs)){  
  21.     array_push($items, $row);  
  22. }  
  23. $result["rows"] = $items;  
  24.   
  25. echo json_encode($result); 

Download the EasyUI example:



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值