tigrang / cakephp-datatable

JQuery DataTable plugin server-side processing component for CakePHP
47 stars 29 forks source link

Implementation with Datatables (Data is still not retrieving) #56

Closed pinkamech closed 9 years ago

pinkamech commented 9 years ago

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

<?php echo $this->fetch('dataTableSettings');?> <?php echo $this->fetch('script');?> <?php foreach($dtResults as $result){ $this->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

<?php echo $this->fetch('script'); ?> <?php echo $this->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

tigrang commented 9 years ago

Is there a url I can access to see what is going on?

pinkamech commented 9 years ago

Is there a way to email you the login details because it is a private testing appln? Thank you and best regards, Rachel

tigrang commented 9 years ago

Sure. tigrangab at gmail On Jan 1, 2015 10:03 PM, "pinkamech" notifications@github.com wrote:

Is there a way to email you the login details because it is a private testing appln? Thank you and best regards, Rachel

— Reply to this email directly or view it on GitHub https://github.com/tigrang/cakephp-datatable/issues/56#issuecomment-68510141 .

pinkamech commented 9 years ago

Issue resolved, Thank you TigRang.

fr0z3nfyr commented 9 years ago

It would be good if either of you posted a summary of the issue and the suggested solution here for other readers. Thanks.