定制 djuki/jqgrider 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

djuki/jqgrider

Composer 安装命令:

composer require djuki/jqgrider

包简介

Generating jqGrid from PHP

关键字:

README 文档

README

#jqGrider

##Introduction

jqGrider is PHP library for generating jqGrid without typing JavaScript code. I created jqGrider for admin part of my applications. I wanted to without much effort present my database tables and datas into ajax grid.

jqGrid is at this moment most complete full-stack javascript grid. At this moment jqGrider supotring only basic and most needed functionality of jqGrid.

With jqGrider you can:

  • Present data from database table
  • Present array data in grid
  • Search grid data with any operator
  • Refresh data grid
  • Paginate results
  • Add custon anonymous function for columns

##Code examples

basic usage of jgGrider

Your main action presenting grid

public function action_grid()
{
    $view = $this->app->forge('View', 'grid');


	$grid = new \JqGrider\Grid(\JqGrider\Grid::DATA_TYPE_JSON);
	$grid
	->addColumn('ID', 'id', 200)
	->addColumn('Full Name', 'name', 450)
	->setUrl('http://localhost/fuelphp2/public/index.php/welcome/grid_data');

	$view->set('grid_js', $grid->getJavaScriptCode(), false);
	
	return $view;
}

Your view with grid

<?=$grid_js?>

Ajax action which will return grid data with ajax call

public function action_grid_data()
{
			
	$grid = new \JqGrider\Grid(\JqGrider\Grid::DATA_TYPE_JSON);
	$grid
	->setRepository(new \App\Model\User())
	->addColumn('ID', 'id', 200)
	->addColumn('Full Name', 'name', 450);
	
	$grid->printRespositoryData();
}

User model need to implement IGridRepository and define two methods getData and countDataRows.

getData can return object with data, and it must have properties like column names. Also it can returna array and key names also must be named as column names.

countDataRows will count data rows considering conditions.

Object Conditions representing search query, and it wil help you to generate database query to calculate rows in search conditions.

namespace App\Model;

use JqGrider\Data\IGridRepository;
use JqGrider\Data\Conditions;

class User implements IGridRepository
{
protected $pdo;

public function __construct()
{	
    // Connect on database with pdo object for example
}

public function getData(Conditions $dataConditions)
{
	$offset = $dataConditions->page == 1 ? 0 : $dataConditions->rowsLimit * ($dataConditions->page - 1);
	$sql = 'SELECT id, name FROM user ';

	if ($dataConditions->search === 'true')
	{
		$sql .= ' WHERE '.$dataConditions->searchCondition;
	}
	
	$sql .=' ORDER BY '.$dataConditions->sortBy.' '.$dataConditions->sort;
	
	$sql .= ' LIMIT '.$dataConditions->rowsLimit.' OFFSET '.$offset;
	
	
	$statement = $this->pdo->prepare($sql, array(\PDO::ATTR_CURSOR => \PDO::CURSOR_FWDONLY));
	@$statement->bindParam(':grid_search_string',$dataConditions->searchString);
	
	if ($statement->execute())
	{
		return $statement->fetchAll(\PDO::FETCH_CLASS);
	}
}

public function countDataRows(Conditions $dataConditions)
{
	$sql = 'SELECT count(id) FROM user';
	if ($dataConditions->search === 'true')
	{
		$sql .= ' WHERE '.$dataConditions->searchCondition;
	}		
	if ($result = $this->pdo->query($sql))
	{
		return $result->fetchColumn();
	}		
}
}

###Using anonymous functions

Anonymous function can be added into Column object to change column content.

        $nameFunction = function ($content)
		{
			return 'Member name is: '.$content;
		};
				
		$grid = new Grid(Grid::DATA_TYPE_JSON);
		$grid->addColumn('Full Name', 'name', 450, $nameFunction);

###Using local data for grid

public function action_grid()
{
	$view = $this->app->forge('View', 'grid');
	
	
	$grid = new Grid(Grid::DATA_TYPE_JSON);
	$grid
	->addColumn('ID', 'id', 200)
	->addColumn('Full Name', 'name', 450);
	
	$grid->setLocalData(array(
		array('id' => 4, 'name' => 'William Harrison'),
		array('id' => 5, 'name' => 'Erick Hawkins'),
		array('id' => 6, 'name' => 'Gene Autry'),
	));

	$view->set('grid_js', $grid->getJavaScriptCode(), false);
	return $view;
}

统计信息

  • 总下载量: 30
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 4
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2012-09-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固