tomaskarlik/select2input
最新稳定版本:0.9.3
Composer 安装命令:
composer require tomaskarlik/select2input
包简介
Select2 form input for Nette
README 文档
README
Install
Download package
composer require tomaskarlik/select2input
Register extension in config.neon
select2: TomasKarlik\Select2Input\DI\Select2InputExtension
Download Select2 or add to bower.json and include JS to your project
"dependencies": { "select2": "~4.0" }
$(document).ready(function() { $('.select2').each(function() { $(this).select2({ ajax: { url: $(this).data('select2-url'), dataType: 'json', // custom parameters } }); }); });
Form usage
$form = new Form; $form->addSelect2('client_id', $clientRepository, 'Klient:') ->setRequired('Vyberte klienta!') ->setResultsPerPage(15); $form->addSelect2Multiple('clients', $clientRepository, 'Klienti:')
Datasource example
namespace App\Model\Repository; use TomasKarlik\Select2Input\ISelect2DataSource; use TomasKarlik\Select2Input\Select2ResultEntity; class ClientRepository implements ISelect2DataSource { /** * @param string $query * @param int $limit * @param int $offset * @return Select2ResultEntity[] */ public function searchTerm(string $query, int $limit, int $offset): array { $return = []; $selection = $this->getClientTable() ->where( 'company ILIKE ?', '%' . $query . '%' ) ->order('company') ->select('client.id, client.company') ->limit($limit, $offset); while ($row = $selection->fetch()) { $result = new Select2ResultEntity; $result->setId($row->id); $result->setText($row->company); $return[] = $result; } return $return; } /** * @param string $query * @return int */ public function searchTermCount(string $query): int { return $this->getClientTable() ->where( 'company ILIKE ?', '%' . $query . '%' ) ->count('*'); } /** * @param mixed $key * @return Select2ResultEntity|NULL */ public function findByKey($key): ?Select2ResultEntity { if ( ! is_numeric($key)) { return NULL; } $client = $this->getClientTable()->wherePrimary($key)->fetch(); if ( ! $client) { return NULL; } $result = new Select2ResultEntity; $result->setId($client->id); $result->setText($client->company); return $result; } }
统计信息
- 总下载量: 13.86k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2018-03-04