JqGrid Search Toolbar filtering
Minggu, 08 Januari 2012 by ewepaksa
selamat datangAda yang pernah attain jqgrid buat nampilin accumulation di application ga gan? Ane ada contohnya yang ini , nah tapi ntu accumulation yang ada di superior toolbarnya kan dari local, kalo punya cardinal dari jsOn, udah nemu pembahasanya di mari gan, tapi berhubung cardinal baru aja jadi programer :malus. cardinal gabisa2 nerapinyya gan :D mohon banuannya bagi yang pernah ngadepin masalah serupa :shakehand, ni kodenya: JSon accumulation source Code: <?php $db = mysql_connect("localhost","root",""); $con = mysql_select_db("seto_project",$db); if(!$con){ echo "Something Problem"; } $page = $_GET['page']; $limit = $_GET['rows']; $sidx = $_GET['sidx']; $sord = $_GET['sord']; if(!$sidx) $sidx=1; function ToSql ($field, $oper, $val) { // we requirement here more modern checking using the identify of the earth - i.e. integer, string, float switch ($field) { case 'nama': default : //mysql_real_escape_string is better if($oper=='bw' || $oper=='bn') convey "'" . addslashes($val) . "%'"; else if ($oper=='ew' || $oper=='en') convey "'%" . addcslashes($val) . "'"; else if ($oper=='cn' || $oper=='nc') convey "'%" . addslashes($val) . "%'"; else convey "'" . addslashes($val) . "'"; } } //array to alter the see type $ops = array( 'eq'=>'=', //equal 'ne'=>'<>',//not equal 'lt'=>'<', //less than 'le'=>'<=',//less than or equal 'gt'=>'>', //greater than 'ge'=>'>=',//greater than or equal 'bw'=>'LIKE', //begins with 'bn'=>'NOT LIKE', //doesn't begin with 'in'=>'LIKE', //is in 'ni'=>'NOT LIKE', //is not in 'ew'=>'LIKE', //ends with 'en'=>'NOT LIKE', //doesn't modify with 'cn'=>'LIKE', // contains 'nc'=>'NOT LIKE' //doesn't contain ); function getWhereClause($col, $oper, $val){ global $ops; if($oper == 'bw' || $oper == 'bn') $val .= '%'; if($oper == 'ew' || $oper == 'en' ) $val = '%'.$val; if($oper == 'cn' || $oper == 'nc' || $oper == 'in' || $oper == 'ni') $val = '%'.$val.'%'; return " WHERE $col {$ops[$oper]} '$val' "; } $where = ""; //if there is no see letter dispatched by jqgrid, $where should be empty $searchField = isset($_GET['searchField']) ? $_GET['searchField'] : false; $searchOper = isset($_GET['searchOper']) ? $_GET['searchOper']: false; $searchString = isset($_GET['searchString']) ? $_GET['searchString'] : false; if ($_GET['_search'] == 'true') { $where = getWhereClause($searchField,$searchOper,$searchString); } $data = mysql_query("SELECT COUNT(*) as calculate FROM tabel_bulanan".$where); $row = mysql_fetch_array($data); $count = $row["count"]; //die($count); $count > 0 ? $total_pages = ceil($count/$limit) : $total_pages = 0; if ($page > $total_pages) $page=$total_pages; $start = $limit*$page - $limit; if($start <0) $start = 0; $data1 = mysql_query("SELECT * FROM tabel_bulanan ".$where." ORDER BY $sidx $sord LIMIT $start, $limit"); $responce->page = $page; $responce->total = $total_pages; $responce->records = $count; $i=0;/*`row_id` , `tahun` , `bulan` , `cabang` , `nmagen` , `sales` , `nmlangganan` , `kota` , `nmbarang` , `nmbarangagen` , `kdgrup` , `nmgrup` , `satuan` , `qty` , `tonase` , `netto` , `harga`*/ while($line = mysql_fetch_array($data1)){ $responce->rows[$i]['id'] = $line["row_id"]; $responce->rows[$i]['cell'] = array($line["row_id"],$line["tahun"],$line["bulan"], $line["cabang"],$line["nmagen"],$line["sales"], $line["nmlangganan"],$line["kota"],$line["nmbarang"], $line["nmbarangagen"],$line["kdgrup"],$line["nmgrup"], $line["satuan"],$line["qty"],$line["tonase"], $line["netto"],$line["harga"],); $i++; } echo json_encode($responce); ?> jqGridnya: Quote: <script type="text/javascript"> $(document).ready(function() { installation = $("#list"), getUniqueNames = function(columnName) { var texts = grid.jqGrid('getCol', columnName); var uniqueTexts = []; var textsLength = grid.jqGrid('getGridParam','data'); var text, textsMap = {}, i; for (i=0;i<textsLength;i++) { book = texts[i]; if (text !== undefinable && textsMap[text] === undefined) { // to effort whether the texts is unequalled we locate it in the map. textsMap[text] = true; uniqueTexts.push(text); } } convey uniqueTexts; }, /*getUniqueNames = function(columnName) { var texts = grid.jqGrid('getCol',columnName), uniqueTexts = [], textsLength = texts.length, text, textsMap = {}, i; for (i=0;i<textsLength;i++) { book = texts[i]; if (text !== undefinable && textsMap[text] === undefined) { // to effort whether the texts is unequalled we locate it in the map. textsMap[text] = true; uniqueTexts.push(text); } } convey uniqueTexts; },*/ buildSearchSelect = function(uniqueNames) { var values=":All"; $.each (uniqueNames, function() { values += ";" + this + ":" + this; }); convey values; }, setSearchSelect = function(columnName) { grid.jqGrid('setColProp', columnName, { stype: 'select', searchoptions: { value:buildSearchSelect(getUniqueNames(columnName) ), sopt:['eq'] } } ); }; grid.jqGrid({ url: 'json/json_tabel_bulanan.php', datatype: "json", mtype: "GET", colNames: ['id','Tahun','Bulan','Cabang','Distributor','Sales ','Nama Langganan', 'Kota','Nama Barang','Nm Barang Distributor','Kd Group','Nm Group', 'Satuan','Qty','Tonase','Netto','Harga'], colModel: [ { name:'row_id', key:true, index:'row_id', hidden:true,editable:false,editrules:{required:tru e}}, { name:'Tahun', index:'Tahun', width:50 }, { name:'Bulan', index:'Bulan', width:40 }, { name:'Cabang', index:'Cabang', width:80 }, { name:'Distributor', index:'Distributor', width:150 }, { name:'Sales', index:'Sales', width:40 }, { name:'Langganan', index:'Langganan', width:200 }, { name:'Kota', index:'Kota', width:200 }, { name:'Nama_barang', index:'Nama_barang', width:200 }, { name:'Nama_barang_d', index:'Nama_barang_d', width:200 }, { name:'Kdgrup', index:'Kdgrup', width:50 }, { name:'Nmgrup', index:'Nmgrup', width:50 }, { name:'Satuan', index:'Satuan', width:20 }, { name:'Qty', index:'Qty', width:20 }, { name:'Tonase', index:'Tonase', width:200 }, { name:'Netto', index:'Netto', width:200 }, { name:'Harga', index:'Harga', width:200 } ], rowNum: 10, rowList: [10,20,30,40,50], sortname: 'row_id', viewrecords: true, rownumbers: true, shrinkToFit:false, width:1000, sortorder: "desc", ignoreCase: true, pager: '#pager', height: "auto", caption: "Tabel Bulanan Distributor" }).jqGrid('navGrid','#pager', {edit:false, add:false, del:false, search:false, refresh:false}); setSearchSelect('Cabang'); setSearchSelect('Tahun'); setSearchSelect('Bulan'); setSearchSelect('Distributor'); setSearchSelect('Langganan'); grid.jqGrid('setColProp', 'Name', { searchoptions: { sopt:['cn'], dataInit: function(elem) { $(elem).autocomplete({ source:getUniqueNames('Name'), delay:0, minLength:0 }); } } }); grid.jqGrid('filterToolbar',{stringResult:true, searchOnEnter:true, defaultSearch:"cn"}); }); </script> Mohon bantuan agan-agan semua :Dterima kasih
Jual Beli Kaskus
Jual Beli Kaskus
Posting Komentar