PHP code example of synergy / synergydatagrid
1. Go to this page and download the library: Download synergy/synergydatagrid 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/ */
synergy / synergydatagrid example snippets
public function gridAction() {
//replace {Entity_Name} with your entity name e.g. 'Application\Entity\User'
$serviceManager = $this->getServiceLocator() ;
$grid = $serviceManager->get('jqgrid')->setGridIdentity({Entity_Name});
$grid->setUrl('your_custom_crun_url'); //optional, if not set the default CRUD controller would be used
return array('grid' => $grid);
}
echo $this->displayGrid($this->grid);
$this->headLink()->appendStylesheet('/jqGrid/css/ui.jqgrid.css')
->appendStylesheet('/css/jquery.ui.datepicker.css')
->appendStylesheet('/plugins/ui.multiselect.css') ;
$this->headScript()->prependFile('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js', 'text/javascript')
->prependFile('http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js', 'text/javascript')
->appendFile('/jqGrid/js/i18n/grid.locale-en.js', 'text/javascript')
->appendFile('/plugins/ui.multiselect.js', 'text/javascript')
->appendFile('/jqGrid/js/jquery.jqGrid.min.js', 'text/javascript') ;
$grid->setDatatype('local');
return array(
.......
'jqgrid' => array (
'column_model' => array(
'my_column' => array(
'align' => 'center',
'formatter' => new Laminas\Json\Expr('your code goes here'),
'unformat' => new Laminas\Json\Expr('your code goes here'),
'edittype' => 'custom',
'editoptions' => array(
'custom_element' => new Laminas\Json\Expr('your code goes here'),
'custom_value' => new Laminas\Json\Expr('your code goes here')
)
),
)
);
$grid->getJsCode()->addCustomScript( new \Laminas\Json\Expr(" and your script here" ));
$grid->getJsCode()->addCustomScript("add your script here");
return array(
.......
'jqgrid' => array (
'column_model' => array(
'my_field' => array(
'isSubGrid' => true
),
)
);
return array(
.......
'jqgrid' => array (
'column_model' => array(
'my_field' => array(
'isSubGridAsGrid' => true
),
)
);
public function crudAction(){ ......
$className = 'your_class_name';
$options['fieldName'] = $this->params()->fromRoute('fieldName', null);
$serviceManager = $this->getServiceLocator();
$grid = $serviceManager->get('jqgrid');
$grid->setGridIdentity($className);
$response = $grid->prepareGridData($this->getRequest(), $options);
.....
}
'jqgrid' => array(
........
'grid_url_generator' => function ($sm, $entity, $fieldName, $targetEntity, $urlType) {
switch($urlType){
.....
case BaseGrid::DYNAMIC_URL_TYPE_ROW_EXPAND:
//@var $helper \Laminas\View\Helper\Url
$helper = $sm->get('viewhelpermanager')->get('url');
$url = $helper('your_route_name',
array(
'your_parameters',
'fieldName' => $fieldName
)
);
return new \Laminas\Json\Expr("'$url?subgridid='+row_id");
}
)
........
$gridId = 'my_unique_id ;
$grid = $serviceManager->get('jqgrid')->setGridIdentity( $className, $gridId);
......
return array(
.......
'jqgrid' => array (
......
'my_unique_id' => array(
.............
)
)
);
......
$grid = $serviceManager->get('jqgrid');
$qb = $grid->getEntityManager()->createQueryBuilder();
$alias = $grid->getModel()->getAlias();
$qb->where($alias . '.your_field', ':param')
->setParameter(':param', 'your_value');
$grid->setCustomQueryBuilder($qb);
........
$queryParam = [
'customFilters' => json_encode(
[
'groupOp' => 'AND',
'rules' => [
[
'field' => 'isActive',
'op' => 'eq',
'data' => 1
],
[
'field' => 'offerCount',
'op' => 'gt',
'data' => 0
],
[
'field' => 'logo',
'op' => 'eq',
'data' => ''
],
]
]
)
];
$grid = $this->getServiceLocator()->get('jqgrid');
$grid->setGridIdentity($className, $entityKey, null, false, $queryParam);
#Configuration Options