承接 carrooi/no-grid 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

carrooi/no-grid

Composer 安装命令:

composer require carrooi/no-grid

包简介

Not a grid for Nette framework

README 文档

README

Build Status Donate

NoGrid

Definitely not a grid, just a simple control for printing data in customized templates with paginator.

It's not a good thing to always just show some automatically generated grid with data, mainly in frontend and that package is for that moments.

BC Break!

Be careful, this package was completely rewritten with version 2.0.0. Please read the new readme.

Features

It has:

  • Paginator with custom templates option
  • Latte macros for simplified templates
  • Views (eg. for archived and not archived data)
  • Different data sources
  • Filtering

It hasn't:

  • Default grid template
  • CSS styles
  • JS scripts
  • Sorting
  • Forms

It may get some of these features in future.

Installation

$ composer require carrooi/no-grid

Now you can register Nette's extension

extensions:
    grid: Carrooi\NoGrid\DI\NoGridExtension

Configuration

grid:
    itemsPerPage: 20
    paginator:
        template: %appDir%/paginator.latte
        templateProvider: App\Grid\TemplateProvider
  • itemsPerPage: default is 10
  • paginator/template: not required
  • paginator/templateProvider: class name for template provider, must be an instance of Carrooi\NoGrid\IPaginatorTemplateProvider interface. Not required

Definition

use Carrooi\NoGrid\DataSource\ArrayDataSource;
use Nette\Application\UI\Presenter;

class BooksPresenter extends Presenter
{

	/** @var \Carrooi\NoGrid\INoGridFactory @inject */
	public $gridFactory;
	
	protected function createComponentBooksGrid()
	{
		$dataSource = new ArrayDataSource([			// Read more about data sources below
			['title' => 'Lord of the Rings'],
			['title' => 'Harry Potter'],
			['title' => 'Narnia'],
		]);
	
		$grid = $this->gridFactory->create($dataSource);
		
		return $grid;
	}

}

Transform data loaded from data source

$grid->transformData(function($line) {
	return [
		'id' => $line->getId(),
		'title' => $line->getTitle(),
	];
});

Printing

<table n:no-grid="booksGrid">
	<thead>
		<tr>
			<th>Title</th>
		</tr>
	</thead>
	<tbody>
		<tr n:no-grid-data-as="$line">
			<td>{$line[title]}</td>
		</tr>
	</tbody>
	<tfoot>
		<tr>
			<th>Display {$noGrid->getCount()} items from {$noGrid->getTotalCount()}</th>
		</tr>
		<tr>
			<td n:no-grid-not-empty>{control booksGrid:paginator}</td>
			<td n:no-grid-empty>No data found...</td>
		</tr>
	</tfoot>
</table>

Latte macros

  • no-grid: Begin grid rendering (similar to {form} macro)
  • no-grid-data-as: Iterate over data from data source and save current line to given variable
  • no-grid-views-as: Iterate over views from current NoGrid and save view data to given variable (see more about views below)
  • no-grid-not-empty: Content will be processed only if there are some data
  • no-grid-empty: Content will be processed only if there are no data
  • no-grid-has-paginator: Content will be processed only if paginator should be rendered

Also you can see that paginator can be rendered with {control booksGrid:paginator}.

These latte macros can't be used as "non-attribute" macros, so there are also variants written in camelCase:

  • noGrid
  • noGridDataAs
  • noGridViewsAs
  • noGridNotEmpty
  • noGridEmpty
  • noGridHasPaginator

Views

Imagine that you want to create for example two tabs - "Active books" and "Sold books". This can be easily done with views.

Definition:

protected function createComponentBooksGrid()
{
	$dataSource = new ArrayDataSource([			// Read more about data sources below
		[
			'title' => 'Lord of the Rings,
			'sold' => true,
		'],
		[
			'title' => 'Harry Potter,
			'sold' => false,
		'],
		[
			'title' => 'Narnia,
			'sold' => false,
		'],
	]);

	$grid = $this->gridFactory($dataSource);
	
	$grid->addView('active', 'Active', function(array &$data) {
		$data = array_filter($data, function($book) {
			return !$book['sold'];
		});
	});
	
	$grid->addView('sold', 'Sold out', function(array &$data) {
		$data = array_filter($data, function($book) {
			return $book['sold'];
		});
	});
	
	return $grid;
}

Display:

<div n:no-grid="booksGrid">
	<ul>
		<li n:no-grid-views-as="$view" n:class="$view->isCurrent() ? active">
			<a href="{$view->getLink()}">
				{$view->getTitle()}
			</a>
		</li>
	</ul>
	<table>
		<!-- same like previous example -->
	</table>
</div>

Filtering

Supported conditions:

  • Condition::SAME (default)
  • Condition::NOT_SAME
  • Condition::IS_NULL
  • Condition::IS_NOT_NULL
  • Condition::LIKE
$form = new Form;
$form->addText('name');
$form->addSubmit('search', 'Search!');

$grid->setFilteringForm($form);

// setting filters is not required
$grid->addFilter('name', Condition::LIKE, [
	Condition::CASE_INSENSITIVE => true,
], function($name) {

	// update value before sending query to database
	return '%'. $name. '%';
});

Now you only have to display form inputs in your template.

Do not render beginning and end of the array, it is rendered automatically!

Data sources

  • Carrooi\NoGrid\DataSource\ArrayDataSource(array)
  • Carrooi\NoGrid\DataSource\Doctrine\DataSource(Doctrine\ORM\QueryBuilder)
  • Carrooi\NoGrid\DataSource\Doctrine\QueryObjectDataSource(Kdyby\Persistence\Queryable, Kdyby\Doctrine\QueryObject)
  • Carrooi\NoGrid\DataSource\Doctrine\QueryFunctionDataSource(Kdyby\Persistence\Queryable, Carrooi\NoGrid\DataSource\DoctrineQueryFunction)

carrooi/no-grid 适用场景与选型建议

carrooi/no-grid 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2015 年 07 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「source」 「data」 「nette」 「grid」 「table」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 carrooi/no-grid 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 carrooi/no-grid 我们能提供哪些服务?
定制开发 / 二次开发

基于 carrooi/no-grid 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 20
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-23