Giter Site home page Giter Site logo

dynatable's Introduction

Deprecated : As the DynatableJs is no longer supported by the authors, this package is deprecated.

Dynatable

Very simple server-side Dynatable handler for Laravel. It handle the ajax calls from the dynatable jquery plugin in the front end.

Using this plugin you can use server-side (ajax) pagination, sorting, global search and specific search. With a simple API you can customize all handlings such as search, sort, column display.

This package is part of WhiteFrame Framework. Features like Widget can be only used when installed from white-frame/white-frame. See WhiteFrame Usage section.

Installation

Laravel 5

Install the package using composer :

composer require white-frame/dynatable:2.*

Laravel 4 : see v1 branch

General Usage

This is a light working example :

<?php
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use WhiteFrame\Dynatable\Dynatable;

class UserController extends Controller
  public function dynatable(Request $request)
  {
    // Get a query builder of what you want to show in dynatable
    $cars = Car::where('year', '=', 2007); // or Car::query() for all cars
    $columns = ['id', 'name', 'price', 'stock'];
    
    // Build dynatable response with your query builder, columns and all input from dynatable font end javascript
    $dynatable = Dynatable::of($cars, $columns, $request->all()));
    
    // ... Here you can customize the result and change columns handling with $dynatable (see example below)
    
    // Build the response and return to the table
    return $dynatable->make();
  }
}

Customize columns handling

Change the content of a column :

$dynatable->column('price', function($car) {
    return number_format($car->price) . ' $';
});

Add a new column for each row :

$dynatable->column('actions', function($car) {
    return '<a href="/car/' . $car->id . '">View</a>';
});

Customize column sorting :

$dynatable->sort('id', function($query, $mode) {
    return $query->orderBy('id', $mode == 'asc');
});

Customize global searching :

$dynatable->search(function($query, $term) {
    return $query->where('name', 'LIKE', '%' . $term . '%');
});

Customize specific column searching :

$dynatable->search('year', function($query, $term) {
    return $query->whereBetween('year', array($term - 5, $term + 5));
});

The use of Dynatable::of

The Dynatable::of static method require 3 parameters :

  • The query builder you want to work with
  • If you want to get an object query builder without doing any where, you can do Car::query().
  • An array containing columns to display
  • The requests input (generally $request->all() is fine).

WhiteFrame Usage

Work to do here ... :)

dynatable's People

Contributors

bradleybernard avatar gaetannaulin avatar ifnotfr avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

dynatable's Issues

How to use Requests ?

Hello,

I'm new to Laravel, but I know the fantastic Dynatable plugin, that's why I'm trying to use it in my project.

Into the view file, how should I use the dynatable function, and with which Request ? I thought requests were used to control forms... I don't understand why a Request is necessary if I want to display a list of elements from my database, and how to use this function.

Would it be possible to get an example of a view and its call to controller's dynatable function ?

Thank you !!

Counting rows for displaying pages could be optimized?

I have noticed the plugin just runs $query->count() (https://github.com/white-frame/dynatable/blob/5.2/src/Dynatable.php#L228) to get the total number of rows to then decide the pagination... however I think it would be nice to be able to either:

  1. Pass in the total row count so we dont have to run ->count() on the query instance
  2. Pass in a different query to do the row count. Basically a stripped down query that doesn't have order by's (same number of rows just in the wrong order).

My use case is this: I am querying a table that has a ton of rows about 1 mil and my query runs fine but the count(*) query from $query->count() is seriously slow and this is because I have an order by and force index on that query. However I don't need an order by or force index on the count statement so I'd like to do one of the two options above.

Difference between query counts?

Hello again!

I was using the PHP Debugbar for Laravel and noticed that two queries were being repeated, both of the queries were count(*). I was looking into the source and found this:

https://github.com/white-frame/dynatable/blob/master/src/Dynatable.php#L225-L226

$datas['totalRecordCount'] = $this->query->count();
$datas['queryRecordCount'] = $this->query->count()

Can it be changed to:

$datas['totalRecordCount'] = $this->query->count();
$datas['queryRecordCount'] = $datas['totalRecordCount'];
//$datas['queryRecordCount'] = $this->query->count();

To reference the previous value since they are the same? It cuts down on one query.

How to use?

Hello,

From the example in the read me it's not very clear how this library works. I may be missing something very crucial but I'm not sure.

So first off I copied the example method dynatable() into my controller and served it. However the route was a get and did not have the request input that dynatable needed like perPage, offset etc so it generated an error. So then I dug into the source and checked the resources/views/ folder to find the script and html blade templates.

I thought ok, I need to get these in my views because to use dynatable I need to setup the table first then use the sample code as an Json api of the table. But, the views has variable $dynatable and $options which the example does not bind or anything like that.

So my next step was to use the example with a get route but this time bind the $dynatable to the html view in the source code that I copied into my folder. Still didn't work.

Went deeper in the source to find this DynatableWidget class which seems like the ticket to figuring this thing out but it confused me still. It had the methods that called the two blade templates and returned a view and it also loaded the views on the register() method so I realized copying the views into my resources folder was a mistake. But I still don't know how to set this up.

How do I access the widget and setup the initial table so I can then copy the readme and set it as the route at which the table gets the data. Sorry for long post just trying to explain my process before asking such a simple question as "how do I use this?"

Doesn't work with Laravel 5.2

I updated to Laravel 5.2 and with this package:

"white-frame/dynatable": "^2.2.1",
composer install
Loading composer repositories with package information
Installing dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: don't install laravel/framework v5.2.6
    - Conclusion: don't install illuminate/support v5.1.28
    - Conclusion: don't install illuminate/support v5.1.25
    - Conclusion: don't install laravel/framework v5.2.5
    - Conclusion: don't install illuminate/support v5.1.22
    - Conclusion: don't install illuminate/support v5.1.20
    - Conclusion: don't install laravel/framework v5.2.4
    - Conclusion: don't install illuminate/support v5.1.16
    - Conclusion: don't install illuminate/support v5.1.13
    - Conclusion: don't install illuminate/support v5.1.8
    - Conclusion: don't install laravel/framework v5.2.3
    - Conclusion: don't install illuminate/support v5.1.6
    - Installation request for white-frame/dynatable ^2.2.1 -> satisfiable by white-frame/dynatable[2.2.1].
    - don't install illuminate/support v5.1.1|don't install laravel/framework v5.2.0
    - don't install illuminate/support v5.1.1|don't install laravel/framework v5.2.1
    - don't install illuminate/support v5.1.1|don't install laravel/framework v5.2.2
    - white-frame/dynatable 2.2.1 requires illuminate/support 5.1.* -> satisfiable by illuminate/support[v5.1.1, v5.1.13, v5.1.16, v5.1.2, v5.1.20, v5.1.22, v5.1.25, v5.1.28, v5.1.6, v5.1.8].
    - Conclusion: don't install illuminate/support v5.1.2
    - Installation request for laravel/framework 5.2.* -> satisfiable by laravel/framework[v5.2.0, v5.2.1, v5.2.2, v5.2.3, v5.2.4, v5.2.5, v5.2.6].

Looks like illuminate/support in white-frame/white-frame composer.json
https://github.com/white-frame/white-frame/blob/master/composer.json#L18 needs to be bumped:

illuminate/support 5.1.* --> illuminate/support 5.2.6

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.