jQuery EasyUI ตารางข้อมูล - เพิ่มสอบถามรายละเอียดเพิ่มเติม
ตัวอย่างนี้แสดงให้เห็นถึงวิธีการที่จะได้รับข้อมูลจากฐานข้อมูลและแสดงไว้ในตารางข้อมูล (DataGrid) ใน จากนั้นแสดงให้เห็นถึงวิธีการแสดงผลการค้นหาตามที่ผู้ใช้ป้อนคำค้นหา
การสร้างตารางข้อมูล (DataGrid)
สร้างฟังก์ชั่นเพจจิ้งกับตารางข้อมูล (DataGrid) และเพิ่มแถบเครื่องมือให้กับมัน
<table id = "TT" class = "easyui-DataGrid" style = "width: 600px; ความสูง: 250px" url = "datagrid24_getdata.php แถบเครื่องมือ" = "# TB" title = "โหลดข้อมูล" iconCls = "ไอคอนบันทึก" rownumbers = "true" เลข = "true"> <thead> <tr> <ฟิลด์ Th = "Itemid" width = "80"> รหัสรายการ </ TH> <ฟิลด์ Th = "ProductID" width = "80"> รหัสสินค้า </ TH> <Th ฟิลด์ = "listprice" width = "80" align = "สิทธิ"> ราคา </ TH> <ฟิลด์ Th = "unitcost" width = "80" align = "สิทธิ"> ต้นทุนต่อหน่วย </ TH> <Th ฟิลด์ = "ATTR1" width = "150"> แอตทริบิวต์ </ TH> <ฟิลด์ Th = "สถานะ" width = "60" align = "center"> สมรส </ TH> </ tr> </ thead> </ table>
แถบเครื่องมือที่กำหนดไว้ดังต่อไปนี้:
<div id = "วัณโรค" style = "padding: 3px"> <span> รหัสสินค้า: </ span> <input id = "itemid" style = "line-height: 26px; ชายแดน: # CCC 1px ของแข็ง"> <span> รหัสสินค้า: </ span> <input id = "ProductID" style = "line-height: 26px; ชายแดน: # CCC 1px ของแข็ง"> <a href="#" class="easyui-linkbutton" plain="true" onclick="doSearch()"> ค้นหา </a> </ div>
เมื่อผู้ใช้ป้อนค่าที่สืบค้นและกดปุ่มแบบสอบถามฟังก์ชั่น 'doSearch' จะถูกเรียกว่า:
ทำงาน doSearch () { $ ( '# Tt'). Datagrid ( 'โหลด' { itemid: $ ( '# Itemid') Val () ,. ProductID: $ ( '# ProductID') Val () }); }
รหัสข้างต้นเรียก 'โหลด' วิธีการในการโหลดข้อมูลตารางใหม่ (DataGrid) ข้อมูล เราต้องผ่าน 'itemid' และ 'ProductID' ข้อโต้แย้งไปยังเซิร์ฟเวอร์
รหัสฝั่งเซิร์ฟเวอร์
รวมถึง conn.php '; ? $ = หน้า isset ($ _ POST [ 'หน้า']) intval ($ _ POST [ 'หน้า']): 1; ? $ แถว = isset ($ _ POST [ 'แถว']) intval ($ _ POST [ 'แถว']): 10; ? $ Itemid = isset ($ _ POST [ 'Itemid']) mysql_real_escape_string ($ _ POST [ 'Itemid']): ''; ? $ ProductID = isset ($ _ POST [ 'ProductID']) mysql_real_escape_string ($ _ POST [ 'ProductID']): ''; Offset $ = ($ หน้า-1) * $ แถว; ผล $ = array (); $ ไหน = "Itemid เช่น '$ itemid% และ ProductID เหมือนกับ' $ ProductID% '"; อาร์เอส $ = mysql_query ( "นับเลือก (*) จากรายการที่" $ ที่.); แถว $ = mysql_fetch_row ($ RS); ผล $ [ "รวม"] = $ แถว [0]; อาร์เอส $ = mysql_query ( "* เลือกจากรายการที่" $ ที่ "ขีด จำกัด $ ชดเชย $ แถว" .. ); $ รายการ = array (); ในขณะที่ ($ แถว = mysql_fetch_object ($ RS)) { array_push ($ รายการ $ แถว); } ผล $ [ "แถว"] = $ รายการ; json_encode Echo ($ result);