EllisLab text mark
Advanced Search
3 of 28
3
   
Ignited DataTables
Posted: 04 November 2010 03:25 AM   [ Ignore ]   [ # 31 ]   [ Rating: 0 ]
Avatar
Joined: 2010-10-28
5 posts

thanks for your fast reply. im really appreciate it.
The path for the button image was correct.
When i check the css for generated table, the DIV for the two button was like this

<div class="dataTables_paginate fg-buttonset ui-buttonset fg-buttonset-multi ui-buttonset-multi paging_two_button" id="list_table_paginate">
<
class="fg-button ui-button ui-state-default ui-corner-left ui-state-disabled" title="Previous" id="list_table_previous"><span class="ui-icon ui-icon-circle-arrow-w"></span></a>
<
class="fg-button ui-button ui-state-default ui-corner-right" title="Next" id="list_table_next"><span class="ui-icon ui-icon-circle-arrow-e"></span></a></div

while it should be the correct way like this

<div class="dataTables_paginate paging_two_button" id="list_table_paginate">
   <
div class="paginate_disabled_previous" title="Previous" id="list_table_previous"></div>
   <
div class="paginate_enabled_next" title="Next" id="list_table_next"></div>
</
div

right now i have no idea where should i change to make it display the correct class

 
Posted: 04 November 2010 04:11 AM   [ Ignore ]   [ # 32 ]   [ Rating: 0 ]
Avatar
Joined: 2010-07-15
90 posts

are you using jquery-ui with your example? coz i admit, i’ve encountered some problems using jquery-ui so i decided to drop using it. aside from that, as i always suggest, try coding datatables first using a static dummy html file and make it work. once it works, it’s easier transfering them to CI…

 Signature 

Ignited Datatables

 
Posted: 04 November 2010 05:36 AM   [ Ignore ]   [ # 33 ]   [ Rating: 0 ]
Avatar
Joined: 2010-10-28
5 posts

thank cyrogenix for enlighten me up. Yup, its about conflict with jquery-ui

after i set bJQueryUI to false from your code sample, then the button apeared

‘bJQueryUI’    : false,

thanks a lot for your help

 
Posted: 04 November 2010 05:58 AM   [ Ignore ]   [ # 34 ]   [ Rating: 0 ]
Avatar
Joined: 2010-07-15
90 posts

i’m very glad i’ve helped (oh wait i did? LOL)...

 Signature 

Ignited Datatables

 
Posted: 04 November 2010 06:15 AM   [ Ignore ]   [ # 35 ]   [ Rating: 0 ]
Avatar
Joined: 2010-10-28
5 posts

LOL

 
Posted: 08 December 2010 12:26 PM   [ Ignore ]   [ # 36 ]   [ Rating: 0 ]
Joined: 2010-08-05
2 posts

this is great.. I use it too. But can you help me for CRUD application?thanks

 
Posted: 08 December 2010 12:28 PM   [ Ignore ]   [ # 37 ]   [ Rating: 0 ]
Joined: 2010-08-05
2 posts

i mean how can this library using for CRUD application?in that libraries i found how it can add addtional column for delete or update. But how can i use it?anyone help me.. so many thanks

 
Posted: 11 December 2010 01:33 PM   [ Ignore ]   [ # 38 ]   [ Rating: 0 ]
Joined: 2010-11-27
2 posts

Hi everybody, its very good library for datatables (i’am a huge fan of datatables) but when i start using CI with Doctrine models relations with database i rewrite this library.

here it is :

Library :

<?php

if (!defined("BASEPATH"))
    exit(
"No direct script access allowed");

/**
 * Datatables(.net) for CodeIgniter
 * 
 * This class/library is an attempt to port the native Datatables php script
 * found at http://datatables.net/examples/data_sources/server_side.html for CodeIgniter
 *
 * @package    CodeIgniter
 * @subpackage libraries
 * @category   library
 * @version    1.0
 * @author     Vincent Bambico <vb@newmediaservices.com.au>
 * @link       http://ellislab.com/forums/viewthread/160896/
 *
 * @upgrade for doctrine by Simonas Ć erlinskas simonas@pc.lt
 */
class Datatables {

    
/**
     * CodeIgniter global variable
     *
     * @global object $ci
     * @name   $ci
     */
    
protected $ci;

    
/**
     * Copies an instance of CI
     */
    
public function __construct() {
        $this
->ci = & get_instance();
    
}

    
/**
     * Builds all the necessary query segments and performs the main query based on passed arguments
     *
     * @param string $model
     * @param string $columns
     * @param string $index
     * @return string
     */
    
public function generate($model$columns$index{


        
/*
         *   WHERE clause
         */
        
$sWhere "";

        if (
$this->ci->input->post("sSearch") != ""{
            $sWhere 
"";

            for (
$i 0$i count($columns); $i++)
                
$sWhere .= $columns[$i] " LIKE '%" $this->ci->input->post("sSearch") . "%' OR ";

            
$sWhere substr_replace($sWhere"", -3);
        
}
        
if ($sWhere == ""{
            $sWhere 
'1';
        
}
        
/*
         *   ORDER clause
         */
        
$sOrder "";

        if (
$this->ci->input->post("iSortCol_0") != null{
            $sOrder 
"";

            for (
$i 0$i intval($this->ci->input->post("iSortingCols")); $i++)
                
$sOrder .= $columns[intval($this->ci->input->post("iSortCol_" $i))" " $this->ci->input->post("sSortDir_" $i) . ", ";

            
$sOrder substr_replace($sOrder"", -2);
        
}

        
if ($sOrder == ""{
            $sOrder 
$columns[1];
        
}

        
/*
         *   LIMIT clause
         */

        
$sLimit "LIMIT ";

        if (
$this->ci->input->post("iDisplayStart") && $this->ci->input->post("iDisplayLength") != "-1")
            
$sLimit .= $this->ci->input->post("iDisplayStart") . ", " $this->ci->input->post("iDisplayLength");
        else 
{
            $iDisplayLength 
$this->ci->input->post("iDisplayLength");

            if (empty(
$iDisplayLength))
                
$sLimit .= "0,10";
            else
                
$sLimit .= "0," $iDisplayLength;
        
}

        $select 
implode(", "$columns);

        
$q Doctrine_Query::create()
                        ->
select($select)
                        ->
from($model)
                        ->
where($sWhere)

                        
/*  in order clause is joined the limit clause, because i did not find how to range result in doctrine  */
                        
->orderBy($sOrder " " $sLimit)
                        ->
setHydrationMode(Doctrine::HYDRATE_ARRAY);
        
$rResult $q->execute();

        
/*
         *  Count all records without ordering and pagination.
         *
         *   if someone knows how to get correct num rows at that query before of all records let me know simonas@pc.lt
         */

        
$q_all Doctrine_Query::create()
                        ->
select('COUNT(id) AS num_rows')
                        ->
from($model)
                        ->
where($sWhere)
                        ->
setHydrationMode(Doctrine::HYDRATE_ARRAY);

        
$rResult_all $q_all->execute();

        
$num_all $rResult_all[0]['num_rows'];

        
$aaData = array();

        
$row 0;
        foreach (
$rResult as $r{
            
for ($i 0$i count($columns); $i++) {
                $aaData[$row][$i] 
$r[$columns[$i]];
            
}
            $row
++;
        
}

        $sOutput 
= array
            (
            
"sEcho" => intval($this->ci->input->post("sEcho")),
            
"iTotalRecords" => "$num_all",
            
"iTotalDisplayRecords" => "$num_all",
            
"aaData" => $aaData
        
);

        return 
json_encode($sOutput);
    
}

in controler you need to define MODEL name not table!

Hope it helps, works very well, and for me its very useful.

 
Posted: 20 December 2010 02:01 AM   [ Ignore ]   [ # 39 ]   [ Rating: 0 ]
Joined: 2009-02-20
1 posts

Hi saimaz,

can u provide your model example for this library?

many thanks! smile

 
Posted: 20 December 2010 05:18 AM   [ Ignore ]   [ # 40 ]   [ Rating: 0 ]
Joined: 2010-11-27
2 posts

hi, here is my category model

<?php

class Category extends Doctrine_Record {

    
public function setTableDefinition() {
        $this
->hasColumn('name''string'255);
        
$this->hasColumn('link''string'255);
    
}

    
public function setUp() {
        $options 
= array(
            
'hasManyRoots' => false,
            
'rootColumnName' => 'root_id'
        
);

        
$this->setTableName(TABLE_PREFIX 'category'); //here i don't know how to 
           //set up table prefix global to doctrine, so i use constant.

        
$this->actAs('Timestampable');
        
$this->actAs('NestedSet'); // its for hierarchical structure

        
$this->hasMutator('name''__create_link');


        
$this->hasMany('Item as Items', array(
            
'local' => 'id',
            
'foreign' => 'category_id'
        
));
        
$this->hasMany('Filter as Filters', array(
            
'local' => 'id',
            
'foreign' => 'category_id'
        
));
        
$this->hasMany('Classification as Classifications', array(
            
'local' => 'id',
            
'foreign' => 'category_id'
        
));
    
}
 
Posted: 20 December 2010 10:50 PM   [ Ignore ]   [ # 41 ]   [ Rating: 0 ]
Avatar
Joined: 2010-07-15
90 posts
Si Jampank - 08 December 2010 05:28 PM

i mean how can this library using for CRUD application?in that libraries i found how it can add addtional column for delete or update. But how can i use it?anyone help me.. so many thanks

if you browsed through the code in the library, at around line 214, you’ll see something like this:

/*
  add additional columns here
  like adding a Delete Row control for example:

  $aaData[$row_key][] = '<a href="#">Delete Button</a>';
*/ 

mmmkaye?

 Signature 

Ignited Datatables

 
Posted: 13 January 2011 12:09 PM   [ Ignore ]   [ # 42 ]   [ Rating: 0 ]
Joined: 2011-01-13
8 posts

Hello,
thank you for the excellent library. It helped me a lot.
Here is adapted for work with PostgreSQL library. Also I did this improvements:
- added here two “virtual” methods produce_cell and produce_row to allow descendands to manipulate cell values and completed rows.
- added additional constructor parameter $hiddenColumns. This columns aren’t shown in the result output but you may access theirs values to compute something.
- The library handles SQL like ‘field1 as f1’ in ordering and filtering.

File is too big for the post and I attached it as zip file.

 
Posted: 14 January 2011 05:29 AM   [ Ignore ]   [ # 43 ]   [ Rating: 0 ]
Joined: 2011-01-14
7 posts

Hi,

Just began playing with DataTables and this tutorial was great except I cannot have a table with more than 4 columns. I have a table with 9 columns and I get the following error via [removed]

DataTables warning (table id = ‘drivers’): Added data (size 9) does not match known number of columns (4)

I checked via firebug and the POST has (iColumns 4) as one of the parameters. I figured this was done dynamically with an array count of the columns you pass to the library but obviously not. I have searched all over the application looking for where this has been set to (4) or if there is a bug stopping the count to work.

Hoping someone could shed some light on the problem

Thanks in advance.

 
Posted: 14 January 2011 05:36 AM   [ Ignore ]   [ # 44 ]   [ Rating: 0 ]
Joined: 2011-01-13
8 posts

Take a look in JS-code where you create DataTable. Please, notice the parameter “aoColumns”.

 
Posted: 14 January 2011 05:54 AM   [ Ignore ]   [ # 45 ]   [ Rating: 0 ]
Joined: 2011-01-14
7 posts

Hey thanks for the quick reply,

Yeah I have tried that, but all the JS looks fine it is doing a count for the aoColumns to create the iColumns param. I was hoping someone had a similar problem with this library to help narrow it down.

Cheers

 
3 of 28
3