yii2-widget-datatables icon indicating copy to clipboard operation
yii2-widget-datatables copied to clipboard

can i use server side processing for this widgets

Open odat opened this issue 9 years ago • 9 comments

hello, can i use the server side processing feature of datatables in this widgets and please if i can get me the example of it, Great work Thanks,

odat avatar Feb 13 '16 09:02 odat

Hello @odat Did you get it work with server side processing?

Hi @fedemotta Nice widget. Specially handy for supporting Yii Grid. But it seems loading at once all data from the dataprovider. How to set it to use the serverSide property? Disabling 'dataprovider' and setting 'clientOptions' => ['serverSide' => true,'ajax' => Url::to(['document/datatables'])] leads to a required 'dataprovider' error. In advance thanks for any hints or tips.

alladas avatar May 03 '16 12:05 alladas

@fedemotta can you add that option or at least provide a lead for someone to fix it? Loading all data when you have bunch of them isn't funny!

mtangoo avatar Dec 30 '17 07:12 mtangoo

@alladas yes thank you

odat avatar Feb 08 '18 09:02 odat

Hi

I am trying to use server side process for datatable, but it is not drawing in table. I get all necessary info in AJAX response, but can not draw. Any ideas ??

haykhov avatar Feb 26 '18 14:02 haykhov

HI @haykhov To get the the server side processing, I finally used this repo. I do not remember all details but my patch has been merged there. You may give it a try

alladas avatar Feb 27 '18 09:02 alladas

Thanks @alladas

haykhov avatar Feb 27 '18 13:02 haykhov

create AjaxController.php public function actionProsessSpm() { $requestData = Yii::$app->request->get(); $start = Yii::$app->request->get('start')==null ? 1 : Yii::$app->request->get('start'); $length = Yii::$app->request->get('length')==null ? 10 : Yii::$app->request->get('length'); $draw = Yii::$app->request->get('draw');//==null ? 10 : Yii::$app->request->get('length'); $columns = array( 0 => '', 1=> 'noreg', 2 => 'nama_skpd', 3 => 'format_spm', 4=> 'tgl_spm', 5 => 'tgl_terima_spm', 6 => '', );

   $sql = "SELECT  a.*,b.nama_skpd from data_spm a"
           . " inner join ref_skpd b on a.id_ref_skpd=b.id"
           . " where 1=1 and a.tahun=$this->tahun_ta";
   
    $data = Yii::$app->db->createCommand($sql)->queryAll();
    
    $totalData = count($data);
    $totalFiltered = $totalData;
         
    if (!empty($requestData['search']['value']))
    {
        $sql.=" AND ( a.noreg LIKE '%" . $requestData['search']['value'] . "%' ";
        $sql.=" OR a.format_spm LIKE '%" . $requestData['search']['value'] . "%'";
        $sql.=" OR b.nama_skpd LIKE '%" . $requestData['search']['value'] . "%')";
      
    }
    $data = Yii::$app->db->createCommand($sql)->queryAll();
    $totalFiltered = count($data);

    $sql.=" ORDER BY a.tgl_terima_spm  ASC  LIMIT " . $start . " ," . 
     $length. "   ";
   
    $result = Yii::$app->db->createCommand($sql)->queryAll();
   
    $data = array();
    $i=1;
    
    foreach ($result as $key => $row)
    {
      
        $nestedData = array();
        $urlView = Url::to(['petugas/data-spm/view', 'id' => $row['id'],'no_spm'=>$row['no_spm'],'noreg'=>$row['noreg'],'id_jenis_spm'=>$row['id_ref_jenis_spm']]);
        $urlUpdate = Url::to(['petugas/data-spm/update', 'id' => $row['id'],'no_spm'=>$row['no_spm'],'noreg'=>$row['noreg'],'id_jenis_spm'=>$row['id_ref_jenis_spm']]);
        $urlDelete = Url::to(['petugas/data-spm/delete', 'id' => $row['id'],'no_spm'=>$row['no_spm'],'noreg'=>$row['noreg'],'id_jenis_spm'=>$row['id_ref_jenis_spm']]);
     $nestedData[] = $i;
        $nestedData[] = $row["noreg"];
        $nestedData[] = $row["nama_skpd"];
        $nestedData[] = $row["format_spm"];
        $nestedData[] = $row["tgl_spm"];
        $nestedData[] = $row["tgl_terima_spm"];
        $nestedData[] = "<a href='$urlView' title='View' aria-label='View' data-pjax='0' > <span class='glyphicon glyphicon-eye-open'></span>"
                . "<a href='$urlUpdate' title='Update' aria-label='View' data-pjax='0'><span class='glyphicon glyphicon-pencil'></span>"
                . "<a href='$urlDelete' title='Delete' aria-label='Delete' data-pjax='0' data-confirm='Are you sure you want to delete this item?' data-method='post'><span class='glyphicon glyphicon-trash'>";
         $data[] = $nestedData;
         $i++;
    }
    
    $json_data = array(
        "draw" => $draw, 
        "recordsTotal" => intval($totalData),
        "recordsFiltered" => intval($totalFiltered),
        "data" => $data   // total data array
    );

    return \yii\helpers\Json::encode($json_data);

}

in setting datatables widget $url = yii\helpers\Url::to(['/ajax/prosess-spm']); $spm = DataTables::widget([ 'dataProvider' => $dataProvider, 'clientOptions' => [ "processing" => true, "serverSide" => true, "ajax" => "$url", //server side

...

atmanegara avatar Dec 20 '19 07:12 atmanegara

@atmanegara what is $spm ?! In widget don't exist thi param...

paskuale75 avatar Jan 06 '20 08:01 paskuale75

@atmanegara what is $spm ?! In widget don't exist thi param...

$spm is not params, its variable, just ignore it

atmanegara avatar Jan 06 '20 12:01 atmanegara