Git Product home page Git Product logo

cakephp-datatable's People

Contributors

ajibarra avatar destinydriven avatar josegonzalez avatar salouri avatar shama avatar tigrang avatar

Stargazers

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

Watchers

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

cakephp-datatable's Issues

Failed to search Data utf8

Hi Tigrang,

The search (Global filter) is not working when I pump utf8 inputs.
Example: ầ, đ, ơ...
My app return 500 Internal Server Error

Here s a screenshot: http://cl.ly/image/2o1C2V1x0b0f

I hope to receive your feedback soon.
Thanks so much.
Regards,
MrHung91

conflict with others requests

Hi,
I have an issue and i dont know how to solve it ...
I installed the plugin and it's working great, my table and data are displayed well, but it looks like all requests in my controller MachinesController are redirected to your plugin.
In my view index i have the table displayed and the action buttons View/Edit/Delete.
When i press Delete, i have this error :

Notice (8): Undefined index: model [APP\Plugin\DataTable\Controller\Component\DataTableComponent.php, line 118]
Notice (8): Undefined index: language [CORE\Cake\I18n\L10n.php, line 379]
Notice (8): Undefined index: locale [CORE\Cake\I18n\L10n.php, line 381]
Notice (8): Undefined index: localeFallback [CORE\Cake\I18n\L10n.php, line 382]
Notice (8): Undefined index: locale [CORE\Cake\I18n\L10n.php, line 385]
Notice (8): Undefined index: charset [CORE\Cake\I18n\L10n.php, line 386]
Notice (8): Undefined index: direction [CORE\Cake\I18n\L10n.php, line 387]

I also have this error in my view "Add" (datatable is not supposed to be used here). I have an ajax request on a button of this page and the previous error appears here.

When I remove the public $components = array( ... ) from the MachinesController, this error does not appear.
Do you have an idea how to solve my problem ? I dont want datatable to be loaded out of index view, it seems the problem is around here ...

Conditions

Hi @tigrang ,
Thanks a lot for this awesome plugin.

I have an issue. How to create a condition by using this plugins?

Let say, I have many posts, and want the table to list only posts in current year. Normally, I can set conditions in find options (or in paginate).

$this->set('posts', $this->paginate('Post', array(
  'YEAR(Post.created)'=>date('Y')
)));

But this code simply didn't work. For now, I just create if condition in View/Posts/datatable/index.ctp, inside the foreach. It work, but the table was messed up.

How do I make the same result with code above by using this plugin?

ajax request is not going through if used in a second action in the same controller

After successfully implementing my index.ctp with this plugin, now I am trying to do the same exact thing with another view (view.ctp) that also includes a datatables set. But its not working! The ajax request doesn't go through at all!
The response type is always "html". Here is how my view.ctp datatables settings:

<script> $(document).ready(function() { $('.dataTable').dataTable({ "bProcessing": true, "bServerSide": true, "bStateSave": true, // when refreshing stay on the same page number "sAjaxSource": src = "Html->url(array('controller' => 'Courses', 'action' => 'view.json',$id , '?' => array('model' => 'Course'))); ?>", "bAutoWidth": false, "bDeferRender": true, "sPaginationType": "full_numbers", "aLengthMenu": [[50, 100, 200], [50, 100, 200]], //[[values],[display]] "iDisplayLength": 50, "oSearch": {"bSmart": false}, "oLanguage": { "sProcessing": "Processing Data...", "sLengthMenu": "Display _MENU_ records" } }); }); </script>

in my view action inside the controller (Courses):
$this->DataTable->settings = array(
'Course' => array( 'recursive' => 0 ) ,
'triggerAction' => array('view') // tried to use array('index', 'view') with no luck
);
$this->DataTable->paginate = array('Course');

Any help please?

Change Page issue fix

I was having trouble with the pagination changing pages, so I modified the DataTableComponent _paginate() method to include this line at the bottom:

$settings['page'] = 1 + ($this->_params['iDisplayStart'] / $limit);

I haven't looking into the documentation enough but I don't think that the offset parameter works.

Note: I am using Cake lib v2.1.3.

Belongs to..

Hi @tigrang .. thanks for the plugin.. how can i use the belongs to relationship in the controller..?
I have two models:
*Collects:
public $belongsTo = array(
'Laborer' => array(
'className' => 'Laborer',
'foreignKey' => 'laborer_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
*Laborer:
public $hasMany = array(
'Collect' => array(
'className' => 'Collect',
'foreignKey' => 'laborer_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
and in my Collects Controller inside index function:
$this->DataTable->paginate = array('Collect');

And i want to display the laborer name.. not just the laborer_id... can i do that?

Thanks in advance.

Problem with admin routing

Hi

It seems your plugin does not detect actions with admin routing (e.g. it does not find admin-index.ctp).

An other problem Ive is that it does not append the model name in "sAjaxSource".

Could you help?

Thanks a lot,
Frank

Smart filtering search not working.

Not sure whats going on. I looked in the datatables documentation to make sure there wasn't something I had disabled or enabled like regex vs smart filtering. From what I can tell everything is as it should. However what I did notice was after each character entered in the search box a GET method is made. When I look at the call I notice that is not breaking up the words by the whitespace as smart filter should work, here s a screenshot http://cl.ly/image/3L3I1x0f1S2c. As you can see the first sSearch has both words rather then splitting them up. Any help would be gratefully appreciated.

How to declare $components & $helpers in individual controllers if I'm using AppController?

Hi, I have declared in my AppController.php some $components and $helpers like this:
public $components = array( 'DebugKit.Toolbar','Session','Acl','Auth');

public $helpers = array('Html' => array('className' => 'BoostCake.BoostCakeHtml'),'Form' => array('className' => 'BoostCake.BoostCakeForm'),...);

Having this configuration in AppController my question is: How to declare 'DataTable.DataTable' component and helper in individual Controllers like Users.php if it's not possible to redeclare classes? Which is the best configuration to use your plugin?
I'm fan of JS datatables but newbie in CakePHP.
Thanks.

how to use it

pardon me...
how tu use it in controller and in the view..?.
i'm new in cakephp :)

Implementation issue

Can you please explain in simple terms with an example, how can I implement this plugin.
I tried to do exactly you have mentioned in the readme doc but not able to render the result. As I am a newbie I am not familiar in this i may be wrong some where. Please help me to implement this.

extra view processing not working

I'm trying to get the extra view processing to work. I disabled autoRender and created a /app/View/[Model]/datatable/[config_name].ctp file.
This file is not processed, all I get is an empty response. What am I doing wrong?

Issue with conditions

public $paginate = array();

public $components = array(
    'DataTable.DataTable' => array(
        'Block'         => array(
            'columns' => array(
                'title'      => 'Título' ,
                'Page.title' => 'Página Mãe' ,
                'Ações'      => NULL ,
                // tells DataTable that this column is not tied to a field
            ) ,
        ) ,
        'triggerAction' => '*'
    )
);


public function solutionscms_index( $id = NULL )
{
    if ( !is_null( $id ) && $this->request->is( 'ajax' ) ) {
            $this->DataTable->paginate                        = array( 'Block' );
            $this->DataTable->settings['Block']['scope'] = array( 'Block.page_id' => $id );
            $this->DataTable->process();
        }
        else if ( is_null( $id ) && !$this->request->is( 'ajax' ) ) {
            $this->redirect(
                array( 'controller' => 'pages' ,
                       'action'     => 'index'
                )
            );
        }
}

Cannot use conditions, even with ['scope']. It's a simple "WHERE page_id = " . $id

The error that I encounter is the Component renders the table without conditions.

When running manually the process() and debugging I can see the return of the database is correct.

SQL query:

SELECT COUNT(*) AS `count` FROM `nexus`.`dmep_blocks` AS `Block` LEFT JOIN `nexus`.`dmep_pages` AS `Page` ON (`Block`.`page_id` = `Page`.`id`)  WHERE `Block`.`page_id` IS NULL

Initialisation script printing in every view

Is it normal that the initialisation script is echoing in all the views of the controller where I'm using the component and the helper?

It's happening even if I don't render a table in a view.

Im using the bug-fixes branch

Conditions not working

conditions in action method not executing.
public function index()
{
$this->paginate['Avatar'] = array(
'conditions' => array('Avatar.id' => '3'),
);
}

Results are also fetching when I comment code in index action.

Is it mandatory to pass a model paramer in ajax request? ex: /avatars?model=Avatar

when i remove model parameter the data is not loading

Add to packagist

I would do it under my name but you might want to have rights to it :)

How to add style

I use DataTable->render(); ?> in my index.ctp view file,
and:

dtResponse['aaData'][] = array( $result['Type']['id'], $result['Type']['name'], $this->Html->link(__(''), array('action' => 'edit', $result['Type']['id']), array('class' => 'button tiny icon-pencil', 'title' => __(''))), ); } in datatable/index.ctp it works and generate table, but i have a quastion, how to add style to them, how to add class to this table. Now I have default cake table view, which look not preety, screenshot: http://postimg.org/image/ozxxarg9j/

Multiple Datatables in the same view and from the same model!

I have two data sets (datatables) in the same view, they both fetch data from the same model. Normally I could just have the same settings in the related action and do the filtering on aoColumns on the front side. However, one data set is filtered based on data from another model, while the other isn't.

Any ideas??

Error on fresh install...

I get this error after follow the intructions on the readme file.

ReferenceError: dataTableSettings is not defined
var settings = dataTableSettings[model];

Missing some step?

What's the right way to paginate an associated model?

I'm trying to paginate an associated model inside of a view called view. The issue is: instead I get te JSON data, I'm getting the HTML of the view where I'm trying to render the Child data. Please help me telling me how it has to be done. Thanks in advance.

From my controller I'm calling the paginate method in the Parent controller as follows:

public funtion view(){
    $this->DataTable->settings['columns'] = array(
        'Child.PROVEEDOR' => 'Supplier',
        'Child.DESTINATARIO' => 'Consignee',
        'Child.NUMFACTURA' => 'Invoice number'
    );
    $this->DataTable->paginate = array('Parent', 'Child');
}

and in my view I render the table:

echo $this->DataTable->render('Child');

I also have the app/View/Parent/datatable/view.ctp file as this:

foreach($dtResults as $result) {
    $this->dtResponse['aaData'][] = array(
        $result['Child']['PROVEEDOR'],
        $result['Child']['DESTINATARIO'],
        $result['Child']['NUMFACTURA'],
    );
}

Building dynamic links in the view based on values from a separate unrelated model

Tigrang thanks a lot for such a great plugin. I am building "delete" links that are based on (if-conditions) data from another un-related model!
Is there anyway to pass a variable/array from the controller to the Users/datatable/index.ctp view?
One I try to pass such array I find it passed to the users/index.ctp instead (the normal way). But I really need this array to build the actions links for the $this->dtResponse['aaData']

One aside question please: how do you add css classes to the in the view? I'm not using the helper. (manually)

Thanks

Is there are way to show two unrelated datatables on a single page?

I have an application, which has a view that needs to contain two datasets - lets say I have View Customer action in my controller. I want to show all contacts that exist with this customer, but I also wish to show all open support requests for this customer. Both of these models are related customer, but not to each other.

What I tried:
In my controller, I put the following code

  $dTcolumns = array(
    'Contact' => array(
      'id' => true,
      'first_name' => true,
      'email' => true,
      'telephone0' => true,
      'Action' => null
    ),
    'Call' => array(
      'id' => true,
      'priority' => true,
      'user' => true,
      'closed' => true,
      'date' => true,
      'Action' => null
    )
  );

  $this->DataTable->settings['triggerAction'] = 'view_client';
  $this->DataTable->settings['columns'] = $dTcolumns;
  $this->layout = "datatables";
  $this->DataTable->paginate = array('Contact','Call');   

  $this->layout = "datatables";
  $this->set('client', $currentClient); 
  $this->render('test_view_client');

And in my View, I have :

  echo $this->DataTable->render('Call',array('class' => 'dataTable table table-striped table-bordered'), $js_call);
  echo $this->DataTable->render('Contact',array('class' => 'dataTable table table-striped table-bordered'), 

$js_contact);

$js_call and $js_contact are both arrays containing the settings for each datatable.

Before I carry on with this path, I am just wondering if what I want is possible.

Cheers,
Gareth

search and Paginate filter

When you set a pagination condition like this one in the controller

$this->paginate['Post'] = array(
  'conditions' => array('OR' => array(...)),
);

If you use the dataTable search you lost your condition, I think the problem is the file Controller / Component / DataTableComponent.php in the function _search() at line 289 from

if (!empty($conditions)) {
  $this->query['conditions']['OR'] = $conditions;
}

Initialization with options

Awesome Plugin. Many thanks!

I'm trying to figure out how to modify the Initialization code. For instance if I wanted full pagers, I would initialize with:

$(document).ready(function() {
    $('#example').dataTable( {
        "sPaginationType": "full_numbers"
    } );
} );

What is the correct way to do this using your plugin?

Implementation with Datatables (Data is still not retrieving)

Hi there,
I've followed all the steps in your Documentation and also have read through several forum posts on the implementation with CakePHP and still can't retrieve any results. I hope you can help me on hand because I've tried all the different solutions on Google (for CakePHP integration with Server Side Processing), however most of them don't work well with me (especially the actions table). Many advanced thanks if you can lend me a hand.

This are the steps I've done: Using the latest Master copy package (below)

  1. Download this: http://github.com/tigrang/cakephp-datatable/zipball/master.
  2. Unzip
  3. Copy and paste the resulting folders into the new 'DataTable' folder in Plugin Folder
  4. Sync on my Console command to make sure it is all added to my Lib and Project etc.
  5. Added 'CakePlugin::load('DataTable');' to bootstrap.config

These are what I've done now: according to your latest documentation.

I want the data from Customers table to be presented in table form (on the Index) page with the action (edit, view, and delete buttons on the table) while looping through all records

CustomerController

public $components = array(
'DataTable.DataTable' => array(
//'triggerAction' => array('index'), // use if your action is not 'index'
'columns' => array(
'id' => 'id', // bSearchable and bSortable will be false
'firstname' => 'First Name', // bSearchable and bSortable will be true, with a custom label Name
// by default, the label with be a Inflector::humanize() version of the key
'lastname' => 'Last Name',
'email' => array(
'bSearchable' => 'customSearch',// will use model callback to add search conditions
),
'mobile_number' => 'Mobile Number',
'address' => 'Address',
'additional_notes' => 'Alt. Contact',
'Actions' => null, // tells DataTable that this column is not tied to a field
),
),
);
$helpers = array(
'DataTable.DataTable',
);
public function index() {
$this->DataTable->paginate = array('Customer');
}

This is based on your "Example - View File" concept:

Next, I have added a new 'index.ctp' file under app/View/Customers/datatable

fetch('dataTableSettings');?> fetch('script');?> dtResponse['aaData'][] = array( $result['Customer']['id'], $result['Customer']['firstname'], $result['Customer']['lastname'], $result['Customer']['email'], $result['Customer']['mobile_number'], $result['Customer']['address'], $result['Customer']['additional_notes'], 'actions', ); } ?>

Added bSearchable callback accordingly on 'Customer' Model page

public function customSearch($field, $searchTerm, $columnSearchTerm, &$conditions) {
if ($searchTerm) {
$conditions[] = array("$field LIKE" => '%' . $searchTerm); // only do left search
}
if ($columnSearchTerm) {
$conditions[] = array($field => $columnSearchTerm); // only do exact match
}
}

Customers/index.ctp
Also fetched 2 scripts that I've read in earlier threads

fetch('script'); ?> fetch('dataTableSettings');?> echo $this->DataTable->render();

Also at this point: I've removed all CakePHP for each loop and TH, TR from the original code written by CakePHP to loop through the records and retrieve them (And it works fine: nothing wrong with retrieving from database)

To be honest,I am stuck here. I have tried to write countless of Javascript functions (from previous threads) and results (no results shown: only table headers that is called from the 'datatable' index.ctp page that are currently displayed).

Please guide me as I've been trying this out for a few days.

Thank you in advance and I hope for your soonest reply or anyone who has successfully implemented this and could help me a hand. Thank you.
Rae

Current result:
1
I am using Datatable 1.10.3 and CakePHP Version 2.5.4

Order/Sort column on server side.

Hi,
I want to show Datatable with sorted data eg. 'Model.example DESC'.
Should I use Cake's 'ORDER' in DataTable->settings (that doesn't work) or try 'aaSorting' from jquery Datatabels? "aaSorting":{"4":"desc"} also doesn't work.

Regards,
Kamil

DateTableComponent: Model not specified for request.

I think I've followed all the steps needed to get this plugin working but I receive the following exception: DateTableComponent: Model not specified for request.

I've verified I am on the right version of CakePHP (2.2.3). I've cloned the plugin in the plugins directory, enabled in bootstrap, added the component to the controller, added the helper, created the necessary view file etc...

I can see within DataTableComponent that this exception is raised if !isset($this->_params['model']). Why is this not being set and what do I need to fix?

Issue when implementing

Hi tigrang. First of all thanks for this awesome Plugin.

In the past my dataTableSettings was empty. Recently I updated to the latest master and now I got

var dataTableSettings = {"Registration":{"bServerSide":true,"sAjaxSource":"\/nexus\/solutionscms\/registrations"}};

that throws me an error:

DateTableComponent: Model not specified for request.

you see, the sAjaxSource doesn't come with ?model=Registration

The SolutionsCMS part is the admin prefix. So the view is solutions_index.ctp

<?php
foreach($dtResults as $result) {
    debug($result);
    $this->dtResponse['aaData'][] = array(
        $result['Registration']['razao_social'],
        $result['Registration']['cnpj'],
        $result['Registration']['email'],
        'actions',
    );
}
public $components = array(
        'DataTable.DataTable' => array(
            'Registration'  => array(
                'columns' => array(
                    'razao_social' => 'Razão Social' ,
                    'cnpj'         => 'CNPJ' ,
                    'email'        => 'E-mail' ,
                    'Ações'        => NULL ,
                    // tells DataTable that this column is not tied to a field
                )
            ) ,
            'triggerAction' => '*'
        ) ,
    );
public
    function solutionscms_index()
    {
        $this->layout                  = 'SolutionsCMS.index';
        // $this->Registration->recursive = 0;
        // $this->set( 'registrations' , $this->paginate() );
        $this->DataTable->paginate = array( 'Registration' );
    }

How use it with query conditions

my code:

public $components = array(
    'DataTable.DataTable' => array(
        'columns' => array(
            'Task.id' => array(
                'bSearchable' => 'plainSearch',
                'bSortable' => true
            ),                  
            'Task.inicio' => array(
                                    'bSearchable' => false,
                'bSortable' => true
            ),
            'Task.fim' => array(
                'bSearchable' => false,
                'bSortable' => true
            ),
            'Task.titulo' => array(
                'bSearchable' => 'plainSearch',
                'bSortable' => true
            )
        )
    )
);

public $helpers = array(
    'Js',
    'DataTable.DataTable'
);

public function index() {

    if ($this->request->is('ajax')) {

        $this->DataTable->paginate();

    }

}

I need put condition in my query, how can i do?

Pagination is not working for me

Hi, I'm trying to get this great plugin work in my app but I'm facing an issue, when I click the pagination buttons, the response brings me the same data so i can't change the page. In the inspector I can see that the request is performing on every click.

Could you help me to get it work? Thanks in advance for you help!!!

This is my implementation:

StatesController.php

<?php
App::uses('AppController','Controller');
class StatesController extends AppController {
    public $components = array(
        'DataTable.DataTable' => array(
            'columns' => array(
                'code' => 'Code',
                'name' => 'Name',
                'Country.name' => 'Country',
            ),
        ),
    );

    public $helpers = array(
        'DataTable.DataTable',
    );

    public function index() {
        $this->DataTable->paginate = array('State', 'Country');
    }
}

index.ctp

<div class="widget widget-simple widget-table">
    <?php 
    $this->DataTable->settings['scriptBlock'] = 'datatable';                    
    echo $this->DataTable->render('State');
    ?>
</div>

States\datatable\index.ctp

<?php
foreach($dtResults as $result) {
    $this->dtResponse['aaData'][] = array(
        $result['State']['code'],
        $result['State']['name'],
        $result['Country']['name'],
    );
}

an this is the value for dataTableSettings var that is being generated by the helper

var dataTableSettings = 
{"State": {
        "sAjaxSource":"\/tms\/states?model=State",
        "bServerSide":true,
        },
"Country":{
        "sAjaxSource":"\/tms\/states?model=Country",
        "bServerSide":true
        }
};

sort by in server side before send to json

I have looked through other similar issues but couldn't solve my problem.

I need to sort or order by mymodel.id DESC before processing to json format.
This mymodel.id is not displayed in view

I open js debug tool and have a looked at my json data. it is not in order

Localisation of column names

Hello,

i have a problem if i want to traduce the column names with __() in my controller settings

public $components = [
    'DataTable.DataTable' => [
        'Badge' => [
            'columns' => [
                'id' => 'Réf',
                'num_serigraphe' => 'Numéro de sérigraphie',
                'num_serie' => 'Numéro de sérigraphie',
                'status' => 'Status',
                'created' => 'Créé le',
                'modified' => 'Modifié le',
                '' => null,
            ],
            'autoData' => false,
            //'autoRender' => false
        ],
    ],
];

Trouble to get it working

Hi,

I'm trying to use the plugin on top of a cakePHP 2.2.2 application. I have followed the README, but I have a problem with the Ajax calls, they are not going to the View/stuff/datatable/action.ctp. Instead, they are directed to View/stuff/action.ctp, which is my regular cake view file.

Then, datatable in the browser complains that the returning data is not JSON (of course it's not). In Firebug, I see an Ajax query going to stuff/action?long-params...

Maybe a reason, but not sure about its real impact : I upgraded the app from cakePHP 2.0, and I'm using JSON views elsewhere.

Help appreciated,
TIA, Charles

$conditions parameter should be &$conditions in custom search function

Tigrang , you have made a great job !
Thanks for this plugin!

$conditions parameter should be &$conditions in custom search function to be taken in account.

'%' . $searchTerm); // only do left search } if ($columnSearchTerm) { $conditions[] = array($field => $columnSearchTerm); // only do exact match } } } Ansley

Have a $_GET conditions

Hello,

i have no solution to send $this->params to a condition ?

public function beforeFilter() {
    parent::beforeFilter();

    $this->DataTable->settings[$this->modelClass]['conditions'] = array(
        $this->modelClass.'.client_id' => $this->Auth->user('client_id'),
        $this->modelClass.'.status' => ??
    );

NetworkError: 500 when trying to search

Hi,

When I try to use quick search eg. I start to type the string to input field there is only "Processing..." info, and nothing happens. FireBug js console returns "NetworkError: 500 when trying to search". Any idea what could be the reason or how can I debug it? Beside quick search everything works fine, paginastion, sort. etc.

Regards
Kamil

Global Search not work.

Hi,
I have the default example working using my Users MVC, the pagination and sorting are working well, but when I make a search this not return the correct records.

There are some key code lines in my implementation.

bootstrap.php
CakePlugin::load('DataTable');

//-----------------------------------------------------------------------------------------
Layout.ctp
echo $this->Html->script('http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js');
echo $this->Html->css('//cdn.datatables.net/1.10.2/css/jquery.dataTables.min.css');
echo $this->Html->script('//cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js');
echo $this->fetch('dataTableSettings');
echo $this->fetch('script')
//-----------------------------------------------------------------------------------------
UsersController.php
public $components = array('Paginator', 'Session',
'DataTable.DataTable' => array(
'triggerAction' => array('index'), // use if your action is not 'index'
'columns' => array(
'id' => true, // bSearchable and bSortable will be false
'username' => 'Usuario', // bSearchable and bSortable will be true, with a custom label Nombre
'name' => array(
'bSearchable' => 'customSearch',// will use model callback to add search conditions
),
'email' => 'email',
'Acciones' => null, // tells DataTable that this column is not tied to a field
),
),
);

public $helpers = array(
    'DataTable.DataTable',
);

public function index() {
$this->User->recursive = 0;
$this->DataTable->paginate = array('User');
}

//-----------------------------------------------------------------------------------------
index.ctp
echo $this->DataTable->render();
//-----------------------------------------------------------------------------------------
datatable/index.ctp

dtResponse['aaData'][] = array( $result['User']['id'], $result['User']['username'], $result['User']['name'], $result['User']['email'], ... 'actions', ); } ?>

//-----------------------------------------------------------------------------------------
Model User.php

public function customSearch($field, $searchTerm, $columnSearchTerm, $conditions) {
if ($searchTerm) {
$conditions[] = array("$field LIKE" => '%' . $searchTerm); // only do left search
}
if ($columnSearchTerm) {
$conditions[] = array($field => $columnSearchTerm); // only do exact match
}
return $conditions;
}

I'm using CakePHP 2.5.3 & DT 1.10.2.
Thanks.

Paging's not working perfectly.

I'm using your plugin for displaying a list products in my site.
Currently, I'm getting an issue about paging, it's saying 'Showing 1 to 100 of NaN entries (filtered from NaN total entries)'.

I'm using helper:
In ProductsController, I added:
public $components = array(
'DataTable.DataTable' => array(
'columns' => array(
'Product.title',
'Product.code',
'Product.qty',
'Product.id',
'Actions' => null
)
),
);

public $helpers = array(
    'DataTable.DataTable'
);

And index() function:
public function index() {
$this->Product->recursive = 0;
$this->DataTable->paginate = array('Product');
}
In layout file, I added the code echo $this->fetch('dataTableSettings'); to above of fetch('script'); ?>

In View/Products/datatable/index.ctp, I added code below:

dtResponse['aaData'][] = array( $result['Product']['title'], $result['Product']['code'], $result['Product']['sku'], $result['Product']['asin'], $result['Product']['qty'], $result['Product']['id'], 'actions', ); } In View/Products/index.ctp, I added code below: Datatable->render();?>

Then I've tried to view list products, I see it's showing good except paging's saying 'Showing 1 to 100 of NaN entries (filtered from NaN total entries)'.
I've used firebug to see responses after running at the first time, and I see:
{"iTotalRecords":3278,"iTotalDisplayRecords":3278,"sEcho":1,"aaData":[["NONE","DILLIGAF Wings ","0110","PAT-0528",null,"16","4826","actions"],["NONE","Proud Son ","0663","",null,"9","5878","actions"],....

I'm using CakePHP version 2.3.2

Can you tell me what's wrong? If you need any another info, please let me know. Thanks for your help.

How to add class attrubite to datatable?

Hi,

I'm using your plugin for showing a list products. I'm using helper to render table. For now, I want to add class attribute to tags in table. So I can bind click event when user click on tags. Can you tell me how I can do this?

One more question, how can I add my callback functions after a row/table is drawed?

Thanks so much.

Way to specify callbacks

is there a way to specify some callback and not get parsed as string to get something like this to the output:

$('#example').dataTable( {
        "fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
            /* Modify the footer row to match what we want */
            var nCells = nRow.getElementsByTagName('th');
            nCells[1].innerHTML = parseInt(iPageMarket * 100)/100 +
                '% ('+ parseInt(iTotalMarket * 100)/100 +'% total)';
        }
} );

if specified as "fnFooterCallback" => "function()..." it get's wrapped in text and never get excuted..

JSON formatting error

hi
thansk for plugin ...

but i have this js error:
DataTables warning (table id = 'DataTables_Table_0'): DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error.

Complain on column name from deep association model - Is this do-able?

I have this situation where I need to use column/value from a deep association model.

Sample Setup like this -


Model Andrews
id
name
belinda_id

belongsto Belinda


Model Belindas
id
name
belinda_child_id

belongsto BelindaChild


Model BelindaChilds
id
name


datatable/index.ctp

foreach ($dtResults as $result) {
$this->dtResponse['aaData'][] = array(
$result['BelindaChild']['name']
)
}


AndrewsController.php

public $components = array(
'DataTable.DataTable' => array(
'columns' => array(
'BelindaChild.name',
)
)
);

public $helpers = array(
'DataTable.DataTable'
)

public function index() {

$this->DataTable->setting['Andrew'] = array(
  'contain' => array(

    'Belinda' => array(
      'fields' => array(
        'id',
        'BelindaChild.id'
      ),
    ),

    'BelindaChild' => array(
      'fields' => array(
         'id',
         'name'
      ),
    ),
  ),

  'fields' => array(
    'id',
    'name',
    'Belinda.id'
  ),
),

}

With above codes, an error message would be like this - SQLSTATE[42S22]: Column not found: 1054 Unknown column BelindaChild.name in field list.

Is there another way to do this to use deep association models or someone has solutions for this?

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.