PHP code example of defyma / yii2-datatable-manual-serverside

1. Go to this page and download the library: Download defyma/yii2-datatable-manual-serverside library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

defyma / yii2-datatable-manual-serverside example snippets


php composer.phar 

    ...
    function actioGetdata()
    {
    	if(Yii::$app->request->isAjax)
        {
            $connection = Yii::$app->get('db');

            $sql = "
                SELECT
                    a.ID,
                    a.KATEGORI,
                    a.DESIGNATOR,
                    a.URAIAN,
                    a.DESIGNATOR_WBS,
                    a.URAIAN_WBS,
                    a.SATUAN_WBS,
                    sum(a.QTY) QTY,
                    a.SATUAN,
                    sum(a.nilai) NILAI
                FROM
                    EPROP_INDIKATIF_SPEND a
                WHERE
                    ( a.DESIGNATOR IS NOT NULL AND a.ID IS NOT NULL )

                    {{DATATABLE_SEARCH}}

                GROUP BY
                    KATEGORI,
                    DESIGNATOR,
                    URAIAN,
                    satuan,
                    a.DESIGNATOR_WBS,
                    a.URAIAN_WBS,
                    a.SATUAN_WBS
            ";

            $data = \defyma\helper\DatatableHelper::generate([
                'connection' => $connection,
                'db_type'    => 'oracle', //db_type : oracle or mysql, default is mysql
                'query'      => $sql,
                'columnSearch' => [ //Column For Search in Table
                    'a.KATEGORI',
                    'a.DESIGNATOR',
                    'a.URAIAN',
                    'a.SATUAN',
                    'QTY',
                    'NILAI',
                    'a.DESIGNATOR_WBS',
                    'a.URAIAN_WBS',
                    'a.SATUAN_WBS'
                ],
                'columnHeader' => [ //Make Sure 'columnHeader' Same as 'column_label' on View
                    'KATEGORI',
                    'DESIGNATOR',
                    'URAIAN',
                    'SATUAN',
                    [   //Custom Value
                        'column' => 'QTY',
                        'value'  => function($data) {
                            return \app\components\WebHelper::formatNumber($data['QTY']);
                        }
                    ],
                    'NILAI'
                ],
                'query_has_where' => true,
                // 'order'           => 'a.KATEGORI ASC',
                /*
                'action_column' => [           //action_column will generate in last of column
                    'template'  => '{delete} {edit} {some_other_button}',
                    'buttons'   => [
                        'delete' => function($data) {
                            return "<button> This Button Delete ".$data['ID']."</button>";
                        },
                        'edit'  => function($data) {
                            return "<button> This Button Edit ".$data['ID']."</button>";
                        },
                        'some_other_button' => function($data) {
                            return "<button> Other Button </button>";
                        }
                    ]
                ]
                */
            ]);

            //if has footer callback
            $data['footer_total'] = 1000;

            // Return Json data table
    	    \Yii::$app->response->format = Response::FORMAT_JSON;
    	    return $data;
        }

    	return $this->render('show_data', []);
    }
    ...