EasyUI Forum

General Category => General Discussion => Topic started by: anugrast on October 01, 2016, 08:43:40 PM



Title: Datagrid multiSort with remoteSort
Post by: anugrast on October 01, 2016, 08:43:40 PM
Hello guys...

I want to made multisort datagrid with remotesort...
Can we used multiSort:true and remoteSort:true together?

I've tried, but it didn't work....

Javascript:
Code:
$('#dgJADKUL').datagrid({
singleSelect:true,rownumbers:true,pagination:true,pageSize:25,pageList: [25,50,100,200,300],
url:'_modul/mod_jadkul/aksi_jadkul.php?act=listJADKUL',multiSort:true,remoteSort:true,
columns:[[
{field:'hari',width:70,align:'center',sortable:true,formatter:formatNamaHari,title:'Hari'},
{field:'jamkuliah',width:90,align:'center',sortable:true,title:'Jam'},
{field:'kodemk',width:100,align:'center',sortable:true,title:'Kode MK'},
{field:'namamk',width:200,align:'left',sortable:true,title:'Nama MK'},
{field:'nama_kelas',width:50,align:'center',sortable:false,formatter:namakelas, title:'Kelas'},
{field:'namados',width:200,align:'left',sortable:true,title:'Dosen Pengasuh'},
{field:'ruang',width:70,align:'center',sortable:true,title:'Ruang'},
{field:'jmlpeserta',width:70,align:'center',sortable:true,title:'Peserta'}
]]
});

PHP:
Code:
if($act=="listJADKUL") {
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 25;
$sort = isset($_POST['sort']) ? strval($_POST['sort']) : 'a.hari,a.jam_mulai';
$order = isset($_POST['order']) ? strval($_POST['order']) : 'asc';

$cari = isset($_POST['cari']) ? mysqli_real_escape_string($conDB,$_POST['cari']) : '';
$offset = ($page-1)*$rows;

$where = "(a.kodemk like '%$cari%' or b.namamk like '%$cari%' or d.nama like '%$cari%')";

$result = array(); $items = array();

$sql ="SELECT a.*,b.namamk,b.sks,b.semester,b.nonkrs,c.nama_kelas,d.nama as namados,d.nama_gelar from ".tblJADKUL." a,".tblMASTERMK." b,".tblMASTERKLS." c,".tblMASTERDOS." d where a.kodefak='$zfak' and a.kodejrs='$zjrs' and a.kodepk='$zprg' and a.kodefak=b.kodefak and a.kodejrs=b.kodejrs and a.kodemk=b.kodemk and a.smtthnakd='$zthn' and a.kelas=c.kode_kelas and a.kodedosen=d.kode and a.kodedosen<>'' and ".$where;
$res = $conDB->query($sql);

$result["total"] = $res->num_rows;

$sql ="SELECT a.*,b.namamk,b.sks,b.semester,b.nonkrs,c.nama_kelas,d.nama as namados,d.nama_gelar from ".tblJADKUL." a,".tblMASTERMK." b,".tblMASTERKLS." c,".tblMASTERDOS." d where a.kodefak='$zfak' and a.kodejrs='$zjrs' and a.kodepk='$zprg' and a.kodefak=b.kodefak and a.kodejrs=b.kodejrs and a.kodemk=b.kodemk and a.smtthnakd='$zthn' and a.kelas=c.kode_kelas and a.kodedosen=d.kode and a.kodedosen<>'' and ".$where." order by $sort $order limit $offset,$rows";
$res = $conDB->query($sql);

while($row = $res->fetch_assoc()){
array_push($items, $row);
}
$result["rows"] = $items;
echo json_encode($result);
}

Can someone help me?

Thanks... :)


Title: Re: Datagrid multiSort with remoteSort
Post by: stworthy on October 02, 2016, 06:35:07 AM
The 'sort' and 'order' parameter value is a string seperated by ',' char. You need to split it and construct the order by clause. Please refer to the code below:
Code:
$sorts = explode(',', $sort);
$orders = explode(',', $order);
$aa = array();
foreach($sorts as $index=>$s){
$o = $orders[$index];
$aa[] = "$s $o";
}
$order_str = join(',', $aa);


Title: Re: Datagrid multiSort with remoteSort
Post by: anugrast on October 02, 2016, 06:24:15 PM
Thanks for your reply stworthy...

I've tried, but it only work at first time... But it doesn't work when I try to sort the other column...

This is my code...

Code:
if($act=="listJADKUL") {
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 25;
$sort = isset($_POST['sort']) ? strval($_POST['sort']) : 'a.hari,a.jam_mulai';
$order = isset($_POST['order']) ? strval($_POST['order']) : 'asc,asc';

        $sorts = explode(',', $sort);
        $orders = explode(',', $order);
        $aa = array();
        foreach($sorts as $index=>$s){
  $o = $orders[$index];
  $aa[] = "$s $o";
        }
        $order_str = join(',', $aa);

$cari = isset($_POST['cari']) ? mysqli_real_escape_string($conDB,$_POST['cari']) : '';
$offset = ($page-1)*$rows;

$where = "(a.kodemk like '%$cari%' or b.namamk like '%$cari%' or d.nama like '%$cari%')";

$result = array(); $items = array();

$sql ="SELECT a.*,b.namamk,b.sks,b.semester,b.nonkrs,c.nama_kelas,d.nama as namados,d.nama_gelar from ".tblJADKUL." a,".tblMASTERMK." b,".tblMASTERKLS." c,".tblMASTERDOS." d where a.kodefak='$zfak' and a.kodejrs='$zjrs' and a.kodepk='$zprg' and a.kodefak=b.kodefak and a.kodejrs=b.kodejrs and a.kodemk=b.kodemk and a.smtthnakd='$zthn' and a.kelas=c.kode_kelas and a.kodedosen=d.kode and a.kodedosen<>'' and ".$where;
$res = $conDB->query($sql);

$result["total"] = $res->num_rows;

$sql ="SELECT a.*,b.namamk,b.sks,b.semester,b.nonkrs,c.nama_kelas,d.nama as namados,d.nama_gelar from ".tblJADKUL." a,".tblMASTERMK." b,".tblMASTERKLS." c,".tblMASTERDOS." d where a.kodefak='$zfak' and a.kodejrs='$zjrs' and a.kodepk='$zprg' and a.kodefak=b.kodefak and a.kodejrs=b.kodejrs and a.kodemk=b.kodemk and a.smtthnakd='$zthn' and a.kelas=c.kode_kelas and a.kodedosen=d.kode and a.kodedosen<>'' and ".$where." order by $order_str limit $offset,$rows";
$res = $conDB->query($sql);

while($row = $res->fetch_assoc()){
array_push($items, $row);
}
$result["rows"] = $items;
echo json_encode($result);
}

Did I miss something?


Title: Re: Datagrid multiSort with remoteSort
Post by: stworthy on October 03, 2016, 05:52:24 AM
When clicking on the column to sort, the 'sort' and 'order' parameter values are sent to server. Please open your browser's debug tool to see if these two parameter values are sent successfully.


Title: Re: Datagrid multiSort with remoteSort
Post by: anugrast on October 03, 2016, 06:55:33 PM
Thanks for your help... It work...