Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/philippfrenzel/yii2-dynatable

yii2 dynatable abstraction
https://github.com/philippfrenzel/yii2-dynatable

Last synced: about 2 months ago
JSON representation

yii2 dynatable abstraction

Awesome Lists containing this project

README

        

yii2-dynatable
=====================
JQuery Dynatable Yii2 Extension
JQuery from: http://dynatable.com

Yii2 Extension by

[![Latest Stable Version](https://poser.pugx.org/philippfrenzel/yii2-dynatable/v/stable.svg)](https://packagist.org/packages/philippfrenzel/yii2-dynatable)
[![Build Status](https://travis-ci.org/philippfrenzel/yii2-dynatable.svg?branch=master)](https://travis-ci.org/philippfrenzel/yii2-dynatable)
[![Code Climate](https://codeclimate.com/github/philippfrenzel/yii2-dynatable.png)](https://codeclimate.com/github/philippfrenzel/yii2-dynatable)
[![Version Eye](https://www.versioneye.com/php/philippfrenzel:yii2-dynatable/badge.svg)](https://www.versioneye.com/php/philippfrenzel:yii2-dynatable)
[![License](https://poser.pugx.org/philippfrenzel/yii2-dynatable/license.svg)](https://packagist.org/packages/philippfrenzel/yii2dynatable)

Installation
============
Package is although registered at packagist.org - so you can just add one line of code, to let it run!

add the following line to your composer.json require section:
```json
"philippfrenzel/yii2-dynatable":"*",
```

And ensure, that you have the follwing plugin installed global:

> php composer.phar global require "fxp/composer-asset-plugin:~1.0"

Changelog
---------

29-11-2014 Updated to latest 2.2.3 Version of the library

Usage
=====

Quickstart Looks like this:

```
= net\frenzel\dynatable\yii2dynatable::widget([
'id' => "nameofthetablethatwillbedynamised"
]);

```

Template for table:

```



Name can contain anything now...
Hobby
Favorite Music




Fred
Roller Skating
Disco


Helen
Rock Climbing
Alternative


Glen
Traveling
Classical

```

extended options are:
```
'clientOptions' => [
'table' => [
'defaultColumnIdStyle' => 'trimDash' //can be "underscore" too - look dynatable.js website for more options
],
'dataset' => [
'ajax' => true,
'ajaxUrl' => Url::to('/your/route/to/json'),
'ajaxOnLoad' => true,
'records' => [],
],
'features' => [
'paginate' => false,
'recordCount' => false,
'sorting' => true,
'search' => false
],
'params' => [
//'queries' => 'queries',
'sorts' => 'sort',
'page' => 'pageCount',
'perPage' => 'perPage',
'offset' => 'offset',
'records' => 'items',
'record' => 'item',
'queryRecordCount' => 'totalCount',
'totalRecordCount' => 'totalCount'
]
]

```
If you set the params like above, the dynatable should work fine with the build in yii2 rest api.

if you are using ajax, you need to ensure, that the response looks like this:
```json
{
"records": [
{
"someAttribute": "I am record one",
"someOtherAttribute": "Fetched by AJAX"
},
{
"someAttribute": "I am record two",
"someOtherAttribute": "Cuz it's awesome"
},
{
"someAttribute": "I am record three",
"someOtherAttribute": "Yup, still AJAX"
}
],
"queryRecordCount": 3,
"totalRecordCount": 3
}
```