Giter Site home page Giter Site logo

monkenwu / tablesigniter Goto Github PK

View Code? Open in Web Editor NEW
13.0 1.0 7.0 245 KB

Tableslgniter is an addins base on CodeIgniter4. It will help you use jQuery Datatables in server side mode.

Home Page: https://tablesigniter.monken.tw/

License: MIT License

PHP 96.26% CSS 1.49% JavaScript 1.71% HTML 0.28% Python 0.25% Hack 0.01%
jquery-datatables codeigniter4 ci4 datatables-serverside library

tablesigniter's Introduction

TablesIgniter

Latest Stable Version Total Downloads License

Tableslgniter is an addins base on CodeIgniter4. It will help you use jQuery Datatables in server side mode.

If you want to get CodeIgniter3 version of Tableslgniter you can go to this git repository.

Visit the sample website and read user guide.

TablesIgniter 基於 CodeIgniter4 。它將可以幫助你在 使用 server side mode 中使用 jQuery Datatables。

如果你希望取得 CodeIgniter3 版本的 Tableslgniter 你可以前往這個 git儲存庫

造訪範例網站與使用指南

Install

Prerequisites

  1. CodeIgniter Framework 4.*
  2. Composer

Composer Install

composer require monken/tablesigniter

Use Library

Declare the following code in the controller that will use TablesIgniter.

use monken\TablesIgniter;

Quick Start

HTML

<table id="firstTable">
    <thead>
        <tr>
            <th>id</th>
            <th>title</th>
            <th>date</th>
        </tr>
    </thead>
</table>

JavaScript

$('#firstTable').DataTable({
    "aoColumnDefs": [{ 
        "bSortable": false,
        "aTargets": [ 0,1,2 ] 
    }],
    "order":[],
    "serverSide":true,
    "searching": false,
    "lengthChange":false,
    "ajax":{
        url:"<?=base_url('home/firstTable')?>",
        type:'POST'
    }
});

Controller

public function firstTable(){
    $model = new HomeModel();
    $table = new TablesIgniter();
    $table->setTable($model->noticeTable())
          ->setOutput(["id","title","date"]);
    return $table->getDatatable();
}
  1. Calling the "setTable()" method must pass in a Query Builder object. TablesIgniter relies on the database query content defined by this object. This object is usually declared in the Model.

  2. When calling the "setOutput()" method, the array must be passed in. The order of the array will affect the order of the data presented by DataTables. The definition of the string must be the same as the field name of the result queried by "setTable()".

  3. Calling "getDatatable()" will get the json string that meets the requirements of jQuery DataTables.

Model

public function noticeTable(){
    $builder = $this->db->table("news");
    return $builder;
}

You are free to use all the methods of Query Builder to meet all your requirements for database query. Finally, you must return the objects generated by Query Builder.

tablesigniter's People

Contributors

monkenwu avatar pooleasee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

tablesigniter's Issues

throws exception

Hi @monkenWu am getting and exception "throw new \Exception("Must be requested by jQuery DataTables.", 1); " from the library and I can't figure out why.

how to implement column search

i tried the method suggested by the datatables documentation, but failed, The following column filter script code that I use

// Setup - add a text input to each footer cell
$('.list_data thead tr:eq(1) th.kolomfilter').each( function () {
        var title = $(this).text();
        // $(this).html( '<input type="text" class="form-control" placeholder="'+title+'.." />' );
        $(this).html( '<input type="text" class="form-control form-control-sm" placeholder="...." />' );
} );
// Apply the search
table.columns('.kolomfilter').every( function () {
  var that = this;
        $( 'input', this.header()).on( 'keyup change clear', function () {
            if ( that.search() !== this.value ) {
                that
                    .search( this.value )
                    .draw();
            }
        } );
} );

Model builder

It's not an issue but I don't know where to write:

CI 4 models have query builder. Therefore; I think your noticeTable function is unnecessary.
We can use $model->builder() directly.

Not working with Searchpanes - Not supported?

Hello (again)

Thanks for sharing your library - it is working very well so far.

I have tried to use the Search panes + Select plugin and it seems it is working to a degree. The search pane is fetching the column results but is not updating the results in the table. Is this plugin not supported or do I have some errors in my code?

image

My code

<script>
    $('#listings').DataTable({
        "aoColumnDefs": [{
            "bSortable": false,
            "aTargets": [1]
        }],
        "order":[],
        "serverSide":true,
        "processing": true,
        "searching": true,
        "searchPanes": {
            "columns": [0,1]
        },
        dom: 'Pfrtip',
        "language" : {
            "decimal":        "",
            "emptyTable":     "No data available in table",
            "info":           "Viser _START_ til _END_ av _TOTAL_ oppdrag",
            "infoEmpty":      "Ingen oppdrag funnet",
            "infoFiltered":   "(filtered from _MAX_ total entries)",
            "infoPostFix":    "",
            "thousands":      ",",
            "lengthMenu":     "Vis _MENU_ oppdrag",
            "loadingRecords": "<h4>Laster inn...</h4>",
            "processing":     "<h4>Laster inn...</h4>",
            "search":         "Søk",
            "zeroRecords":    "Vi fant dessverre ingen oppdrag",
            "paginate": {
                "first": "Første",
                "last": "Siste",
                "next": "Neste",
                "previous": "Forrige",
            }
         },
        "lengthChange":true,
        "pageLength":10,
        "ajax":{
            url:"<?=base_url('/dashboard/firstTable')?>",
            type:'POST'
        }
    });
</script>

Model

    public function noticeTable(){
        $builder = $this->db->table("jobs");
        return $builder;
    }

Controller

    public function firstTable(){
        $this->jobs = new \App\Models\Jobs();
        $table = new TablesIgniter();
        $table->setTable($this->jobs->noticeTable())
            ->setOutput(['jobs_title', 'jobs_created_at'])
            ->setDefaultOrder("jobs_id","DESC")
            ->setSearch(["jobs_title"]);
        return $table->getDatatable();
    }

Custom icon as an output on table

Hello!

First thing to say is, thanks for this great library. It helped me a lot.

I tried to make the "Project Status" output with custom icons like this:

image

It can be done easily with a client-side, but I'm a bit confused on how to do it with the server-side (with your library, of course).

I tried with this code snippet, but it only returns a "Detail Button"

public function fetchProjectData()
	{
		$table = new TablesIgniter();
		$table->setTable($this->projectModel->noticeTable())
			->setDefaultOrder('project_name', 'ASC')
			->setOrder([
				'project_name', 'client_name', 'pm_name',
				'start_date', 'finish_date', 'project_status', null
			])
			->setSearch(['project_name', 'client_name', 'pm_name', 'project_status'])
			->setOutput([
				'project_name', 'client_name', 'pm_name', 'start_date',
				'finish_date', $this->projectStatus('project_status'), $this->projectModel->button()
			]);
		return $table->getDatatable();
	}

public function projectStatus($project_status)
	{
		if ($project_status == 'hold') {
			$closureFun = function () {
				return '<span class="badge rounded-pill bg-primary">Hold</span>';
			};
		} else {
			$closureFun = function () {
				return '<button type="button" class="btn btn-info">Detail</button>'; //detail button
			};
		}
		return $closureFun;
	}

My goal is, the output can be the custom icons I've made, just like when I return a Button with the closure style.
I'm still learning web development with CI4..

Thanks in advance.

Undefined index: draw

I tried to follow the guide and get the following error

Undefined index: draw

Not sure what the problem is?

Problems with Search

I'm Using Codeigniter 4.1.1 with Tablesigniter.

In my Model I use the Builder to filter Data before. For example

public function frontTable(): BaseBuilder
    {
        $builder = $this->db->table($this->table);
        $builder->where('status', 1);
        return $builder;
    }

When the Table is loaded filtering works and only entries where status =1 are shown. If I use the search, all entries are shown. Please help me.

Wanna ask

Hello, this is great library. I will add this packages to my project. But i wanna little ask, why this packages is whole ci4 starter not small for library? Thanks.

class not found

hi, i'm trying to implement this library with my ci-4 app.
but this always return error class not found.
i've already install composer and use monken\TablesIgniter on my app controller.
idk why.. i'm currently use codeigniter 4.1.1.
and there is my sample sourcecode.

`
namespace App\Controllers;
use App\Controllers\BaseController;
use monken\TablesIgniter;
use App\Models\Transaction;
use CodeIgniter\API\ResponseTrait;
use CodeIgniter\RESTful\ResourceController;

public function otherdatatables()
{
$table = new TablesIgniter();
$Transaction = new Transaction();
$table->setTable($Transaction->datatableList())
->setDefaultOrder("id", "DESC")
->setOutput([
"id",
"buyer",
"created_at as created"
]);
return $table->getDatatable();
}
`

Problems with PHP 8

I tried to install the library but, after do "composer update" get this error:

composer update monken/tablesigniter
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Root composer.json requires monken/tablesigniter ^v1.2.0 -> satisfiable by monken/tablesigniter[v1.2.0].
- monken/tablesigniter v1.2.0 requires php ^7.1 -> your php version (8.0.1) does not satisfy that requirement.

:(

EDIT: The problem was in composer.json change "monken/tablesigniter": "^v1.2.0" for "monken/tablesigniter": "^1.1"

CI 3

Hi
Does this addition work with the version CodeIgniter 3.1.11?
Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.