ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Ignited DataTables

July 15, 2010 2:51am

Subscribe [119]
  • #31 / Nov 04, 2010 2:45am

    cryogenix

    90 posts

    thank you for your feedback. since you are using two_button as your sPaginationType, the NEXT and PREVIOUS buttons will actually be there. however if you are seeing it as text, then i’m suspecting you have some image directory issues because as far as i’ve tested, two_button mode should look like this (by default):

    http://img257.imageshack.us/img257/2687/2but.png

    while on the other hand, full_numbers mode should look like this:

    http://img222.imageshack.us/img222/1690/fullnum.png

    both of them render correctly in my tests so i think that there is nothing wrong with the code. do check your image directories (in the css: datatables.css) if they point to the previous and back buttons correctly.

    cheers
    hope it helps…

  • #32 / Nov 04, 2010 3:25am

    Dermis

    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">
    <a 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>
    <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

  • #33 / Nov 04, 2010 4:11am

    cryogenix

    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…

  • #34 / Nov 04, 2010 5:36am

    Dermis

    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

  • #35 / Nov 04, 2010 5:58am

    cryogenix

    90 posts

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

  • #36 / Nov 04, 2010 6:15am

    Dermis

    5 posts

    LOL

  • #37 / Dec 08, 2010 11:26am

    Si Jampank

    2 posts

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

  • #38 / Dec 08, 2010 11:28am

    Si Jampank

    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

  • #39 / Dec 11, 2010 12:33pm

    saimaz

    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 <a href="http://datatables.net/examples/data_sources/server_side.html">http://datatables.net/examples/data_sources/server_side.html</a> for CodeIgniter
     *
     * @package    CodeIgniter
     * @subpackage libraries
     * @category   library
     * @version    1.0
     * @author     Vincent Bambico <[email protected]>
     * @link       <a href="http://ellislab.com/forums/viewthread/160896/">http://ellislab.com/forums/viewthread/160896/</a>
     *
     * @upgrade for doctrine by Simonas Ć erlinskas .(JavaScript must be enabled to view this email address)
     */
    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 .(JavaScript must be enabled to view this email address)
             */
    
            $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.

  • #40 / Dec 20, 2010 1:01am

    andriecool

    1 posts

    Hi saimaz,

    can u provide your model example for this library?

    many thanks! 😊

  • #41 / Dec 20, 2010 4:18am

    saimaz

    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'
            ));
        }
    }
  • #42 / Dec 20, 2010 9:50pm

    cryogenix

    90 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

    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?

  • #43 / Jan 13, 2011 11:09am

    HiTek

    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.

  • #44 / Jan 14, 2011 4:29am

    Gizmo84

    6 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.

  • #45 / Jan 14, 2011 4:36am

    HiTek

    8 posts

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

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases