PHP code example of jenzri-nizar / zf3-jquerydatatable

1. Go to this page and download the library: Download jenzri-nizar/zf3-jquerydatatable 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/ */

    

jenzri-nizar / zf3-jquerydatatable example snippets


"jenzri-nizar/zf3-jquerydatatable": "^1.0"

composer update

'modules' => array(
    '...',
    'Zend\Paginator',
    'Zend\Db',
    'Zf3\Jquerydatatable'
),

$radio = new Element\Radio('rd');
$radio->setLabelAttributes(array('class' => 'col-md-4'));
$radio->setValueOptions(array(
            'Item 1' => "Item 1",
            'Item 2' => "Item 2",
            'Item 3' => "Item 3",
 ));

$range = new Element\Range('range');
$range ->setAttributes(array(
                'min'  => '0',
                'max'  => '100',
                'step' => '5',   
            ));
$range->setAttribute("class","form-control");

$Text=new \Zend\Form\Element\Text("test",[]);
$Text->setAttribute("class","form-control");

$this->DataTable()->setConfig('Album_1',array(
            "columns"=>array(
                "id"=>[
                    "label"=>"Id",
                    "search"=>
                        [
                            "element"=>$Text
                        ]

                ],
                "artist" =>[
                    "label"=>"Artist",
                    "search"=>
                        [
                            "element"=>$Text
                        ]

                ],
                "title"=>[
                    "label"=>"Title",
                    "search"=>
                        [
                            "type"=>"between",
                            "from"=>$Text,
                            "to"=>$Text
                        ]
                ],
            ),
            "lang"=>"fr",
            "limit"=>10,
            "ajax"=>true,
            "model"=>$this->getEvent()->getApplication()->getServiceManager()->get('AlbumTable'),
));

$this->DataTable()->setConfig('Album_2',array(
            "columns"=>array(
                "id"=>[
                    "label"=>"Id",
                    "search"=>
                        [
                            "element"=>$range
                        ]

                ],
                "artist" =>[
                    "label"=>"Artist",
                    "search"=>
                        [
                            "element"=>$radio
                        ]

                ],
                "title"=>[
                    "label"=>"Title",
                    "search"=>
                        [
                            "element"=>$Text

                        ]
                ],
            ),
            "search_label"=>"Recherche",
            "lang"=>"fr",
            "limit"=>10,
            "ajax"=>true,
            "model"=>$this->getEvent()->getApplication()->getServiceManager()->get('AlbumTable'),
        ));

 echo $this->datatable("Album_1");

$this->DataTable()->setConfig('Album_2',array(
            "columns"=>array(
                "id"=>[
                    "label"=>"Id",
                    "search"=>
                        [
                            "element"=>$Text
                        ]

                ],
                "artist" =>[
                    "label"=>"Artist",
                    "search"=>
                        [
                            "element"=>$radio
                        ]

                ],
                "title"=>[
                    "label"=>"Title",
                    "search"=>
                        [
                            "element"=>$Text

                        ]
                ],
            ),
            "search_label"=>"Recherche",
            "lang"=>"fr",
            "limit"=>5,
            "ajax"=>true,
            "model"=>$this->getEvent()->getApplication()->getServiceManager()->get('AlbumTable'),
            "buttons"=>[
                "class"=>"btn-buttons",
                "template" => "{update} {delete}",
                "buttons" => [
                    "delete"=>[
                        "url"=>"#/id={id}",
                        "click"=>"$(document).on('click','.ClassDeleteAjax',function(){alert('test');return false;});",
                        "html"=>"<span class='btn btn-danger glyphicon glyphicon-trash'></span>",
                        "class"=>"ClassDeleteAjax",
                        "attr"=>[
                            "data-id"=>"{id}",
                            "data-text"=>"Text",
                            "data-artist"=>"{artist}",
                        ]
                    ],
                    "update" => [
                        "url"=>"#/id={id}&artist={artist}",
                        "click"=>"",
                        "html"=>"<span class='btn btn-success glyphicon glyphicon-edit'></span>",
                        "class"=>"ClassUpdate",
                        "attr"=>[
                            "data-id"=>"{id}",
                            "data-text"=>"Test",
                        ]
                    ],
                ],
            ]
        ));