• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

nacasha/CIgniter-Datatables: CodeIgniter library for Datatables server-side proc ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

nacasha/CIgniter-Datatables

开源软件地址:

https://github.com/nacasha/CIgniter-Datatables

开源编程语言:

PHP 100.0%

开源软件介绍:

CIgniter-Datatables

CodeIgniter library for Datatables server-side processing / AJAX, easy to use :3

Important changes

Commit : 870b1caadbf9a2756b513c1e58fe5f153086b399

Change basic API to create Datatables

  • Old : $this->datatables->new();
  • New : $this->datatables->init();

Change API to init created datatables config

  • Old : $this->datatables->init();
  • New : $this->datatables->create();

Features

  1. Easy to use.
  2. Generates Datatable and JSON for server side processing in just one controller.
  3. Multiple Datatables in one page.
  4. Use CodeIgniter Query Builder Class to produce query (support all functions). Read Documentation
  5. Support columns rendering/formatting.
  6. Able to define searchable table columns.
  7. Configurable datatables options. Read Documentation

Wiki

  1. Basic Usage

Installing

  • jQuery

     <script type="text/javascript" language="javascript" src="//code.jquery.com/jquery-1.11.1.min.js"></script>
    
  • DataTables

     <script type="text/javascript" language="javascript" src="//cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js"></script>
    
  • CIgniter Datatables Library

    Download and place to your codeigniter libraries folder

Basic Example

Controllers

$this->load->library('Datatables');

$dt_authors = $this->datatables->init();

$dt_authors->select('*')->from('authors');

$dt_authors
    ->style(array(
	'class' => 'table table-striped table-bordered',
    ))
    ->column('First Name', 'first_name')
    ->column('Last Name', 'last_name')
    ->column('Email', 'email');

$this->datatables->create('dt_authors', $dt_authors); 

Views

$this->datatables->generate('dt_authors');

// Add this line after you load jquery from code.jquery.com
$this->datatables->jquery('dt_authors');

Usage

Use CodeIgniter Query Builder Class/Active Record to build SQL query. Read Query Builder Documentation

Create new variable to create initialize Datatables.

$dt_authors = $this->datatables->init();

Select columns and table. NOTE : Don't use ->get() or other method for executing the query, let the library do for you.

$dt_authors->select('first_name, last_name, email')->from('authors');

Use column() to add column to datatables.

$dt_authors
    ->column('First Name', 'first_name')
    ->column('Last Name', 'last_name')
    ->column('Email', 'email');

Create datatables instance using created configurations ($dt_authors) and provide unique name ('dt_authors')

$this->datatables->create('dt_authors', $dt_authors);

Generate table in views

$this->datatables->generate('dt_authors);
$this->datatables->jquery('dt_authors);

Column Rendering/Formatting

// $dt_authors is an example 
$dt_authors
    ->column('Name', 'name', function($data, $row){
    	return $row['first_name'] .' '. $row['last_name'];
    })
    ->column('Age', 'age', function($data, $row){
		return $data . ' years old';
    })
    ->column('Email', 'salary');

$t->create();

Custom searchable column

// $dt_authors is an example 
$dt_authors
    ->searchable('first_name, age'); 	// table columns
    // -> ... other chain methods

Datatable Options

DataTables and its extensions are extremely configurable libraries and almost every aspect of the enhancements they make to HTML tables can be customised.

You can use set_options add the options.

Note : Second parameter will not produce single quote, wrap option value with double quotes to produce single quotes or use escaping.

// $dt_authors is an example 
$dt_authors
    ->set_options('searching', 'false')			// searching : false
    ->set_options('pagingType', '\'simple\'')		// pagingType : 'simple'
  //->set_options('pagingType', "'simple'")
    ->set_options('lengthMenu', '[ 10, 25, 50, 75, 100 ]')	 // lengthMenu : [ 10, 25, 50, 75, 100 ]

You can use array too ...

->set_options(array(
    array('searching', 'false')
    array('pagingType', "'simple'")
    array('lengthMenu', '[ 10, 25, 50, 75, 100 ]')
));

Use set_options('ajax.data', '...') to override ajax data options

Show paginatin in top and bottom of Datatables

This is workaround incase you want to show pagination in both top and bottom of Datatables. I will create new API with the other changes when it ready.

Go to DatatablesBuilder.php and search for '$output' at line 176 and add this lines (#7)

    \"pagingType\": \"full_numbers\",
    \"sDom\": '<\"top\"lfprtip><\"bottom\"><\"clear\">',

Styling Tables

You can use style to add table tag attributes to styling your table.

// $dt_authors is an example 
$dt_authors
    ->style(array(
        'class' => 'table table-bordered table-striped',
    ))

Changelog

Version 1.5

  • Add new API to override ajax data
  • Support multiple datatables in one page
  • Fix unable to search on field contains null

Version 1.1

  • Fix searching when use alias for columns
  • Remove query_builder, use direct select() to build query

Version 1.0

  • Initial Release (Development)



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap