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]
  • #421 / Aug 02, 2013 8:08am

    nmoynihan

    2 posts

    I am trying to output some data formatted differently for each row, using $this->datatables->add_column(); but it is not working for some reason.

    Controller Code:

    $this->datatables->select('project_id, name, status, end_date')
    ->unset_column('end_date');
       $this->datatables->add_column('end_date', check_deadline('$1'), 'end_date')    
       $this->datatables->from('projects');
       echo $this->datatables->generate();

    Helper Function:

    function check_deadline($date)
     {
      if (trim($date) == '0000-00-00')
      {
       return "Ongoing";
      }
      else
      {
       return trim($date);
      }
     }

    As the end result, I either get EVERY row to say ‘Ongoing’ or as the actual date, including if it is 0000-00-00.

    Am I using this function in the wrong way? Any help greatly appreciated.

    EDIT: So I am thinking this function just gets evaluated once, and the variable replacement is done AFTER the function is evaluated. Is there a way I can make it do what I want? Thanks!

  • #422 / Aug 06, 2013 1:03pm

    ηυмвєяσηє

    109 posts

    >add_column(‘end_date’, ‘$1’, ‘check_deadline(“end_date”)’) 

    >add_column(‘end_date’, ‘$1 $2’, ‘check_deadline(“end_date”) , status’) 

    The usage is like this.

  • #423 / Aug 09, 2013 6:33pm

    nmoynihan

    2 posts

    >add_column(‘end_date’, ‘$1’, ‘check_deadline(“end_date”)’) 

    >add_column(‘end_date’, ‘$1 $2’, ‘check_deadline(“end_date”) , status’) 

    The usage is like this.

    Thanks!

  • #424 / Aug 15, 2013 7:33pm

    bluehat09

    6 posts

    Thanks!

    I have created a small tutorial for how to use ignited datatables, hope it helps you
    http://www.ahmed-samy.com/codeigniter-full-featrued-jquery-datatables/

  • #425 / Aug 20, 2013 4:52am

    ninjayan

    72 posts

    "sAjaxSource": "<?php echo base_url(); ?>document_directory/get_transactions",

    This line of js datatable is used for getting records. My concern now is how can I protect the controller function in getting transactions because everyone can directly access the controller function and show all the records.

  • #426 / Aug 21, 2013 11:39pm

    cryogenix

    90 posts

    Hi, i switched to start using this library but im having an (maybe noobie) issue.  The library always returns 100 rows when I have 3000+ in the table I want to show, here is what I got using the original script and processing the results in the view with a foreach loop:

    Showing 1 to 20 of 3080 entries

    And with this library i got this:

    Showing 1 to 20 of 100 entries

    Edit:
    Im adding the code so anyone can have a better idea and help me.

    This is in my view, the sDom parameter is something to do with the bootstrap framework:

    $('#peopletable').dataTable( {
                    "sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
                    "aaSorting": [[1,'asc']],
                    "oLanguage": spanish,
                    "sPaginationType": "bootstrap",
                    "iDisplayLength": 20,
                    "bProcessing": true,
                    "bServerSide": false,
                    "sAjaxSource": "pacientes/json_people",
                    "fnServerData": function(sSource, aoData, fnCallback){
                         $.ajax ({
                          'dataType': 'json',
                          'type'    : 'POST',
                          'url'     : sSource,
                          'data'    : aoData,
                          'success' : fnCallback
                         });
                        }
                });

    And this is the json_people function in my controller:

    function json_people()
     {
      $this->load->library('Datatables');
      $this->datatables
          ->select('[removed fields]')
          ->from('people');
    
      echo $this->datatables->generate();
     }

    Im sorry if this have something to do with some basic parameter I just dont know how to make it work.  Also Im working with postgresql so I dont know either if this could be some pg related issue.

    Edit:  Forgot to ask about something else, i cant make this work when i set “bServerSide”: true

    hi there. this issue has been resolved as of the latest push (thanks to blyxx86). please update your copy of ignited datatables.

  • #427 / Aug 27, 2013 2:53am

    ninjayan

    72 posts

    I randomly get 403 Forbidden error when using the datatables search feature. I don’t know why? Server timeout?

  • #428 / Aug 27, 2013 5:39pm

    jovenmdavid

    1 posts

    Hi All,

    I use codeigniter and datatables i have a problem when i use group_by(), my tables has show 10 rows only but on the bottom of the tables it says “Showing 1 to 10 of 15 entries”

    is group_by() is not grouping properly?

    if the records are not group then there is 15 rows, but i need to group by name so after grouping it will who only 10 rows but on the bottom says 15 total entries.

    Please help.

  • #429 / Aug 28, 2013 6:34pm

    afirdaus

    3 posts

    hi i got problem with edit_column

    user_m.php (model file)

    function getListpppmbPaging()
    {
         $this->load->library('datatables');
         $this->datatables->select('*,BARANG_TGL_REG')->from('tb_barang');
         $this->datatables->where('BARANG_STATUS !=','BATAL');
         $this->datatables->where('BARANG_STATUS !=','SELESAI');
         $this->datatables->edit_column('BARANG_TGL_REG', '$1','waktuid("BARANG_TGL_REG")');
         return $this->datatables->generate();
    }
    
    function waktuid($tgl){
     $tahun = substr($tgl,0,4);
     $bulan = substr($tgl,5,2);
     $tanggal = substr($tgl,8,2);
            $tglnya = date("d-M-Y H:i:s",strtotime($tgl));
            $jam = substr($tgl, 11,5);
     $lengkap=$tanggal.'-'.$bulan.'-'.$tahun.' '.$jam;
             return $lengkap;   
    }

    but datatable shown “waktuid(“BARANG_TGL_REG”)” in column, and then i tried

    $this->datatables->edit_column('BARANG_TGL_REG', '$1','callback_waktuid("BARANG_TGL_REG")');

    or

    $this->datatables->edit_column('BARANG_TGL_REG', '$1','$this->waktuid("BARANG_TGL_REG")');

    the result is same..

    i think call_user_func_array in exec_replace function datatables.php file only identifier built in php function like trim, substr, etc..

    please help me how parsing local function from edit_column.


    Thanks, sorry my english is bad

     

  • #430 / Aug 29, 2013 7:12am

    afirdaus

    3 posts

    hi i got problem with edit_column

    user_m.php (model file)

    function getListpppmbPaging()
    {
         $this->load->library('datatables');
         $this->datatables->select('*,BARANG_TGL_REG')->from('tb_barang');
         $this->datatables->where('BARANG_STATUS !=','BATAL');
         $this->datatables->where('BARANG_STATUS !=','SELESAI');
         $this->datatables->edit_column('BARANG_TGL_REG', '$1','waktuid("BARANG_TGL_REG")');
         return $this->datatables->generate();
    }
    
    function waktuid($tgl){
     $tahun = substr($tgl,0,4);
     $bulan = substr($tgl,5,2);
     $tanggal = substr($tgl,8,2);
            $tglnya = date("d-M-Y H:i:s",strtotime($tgl));
            $jam = substr($tgl, 11,5);
     $lengkap=$tanggal.'-'.$bulan.'-'.$tahun.' '.$jam;
             return $lengkap;   
    }

    but datatable shown “waktuid(“BARANG_TGL_REG”)” in column, and then i tried

    $this->datatables->edit_column('BARANG_TGL_REG', '$1','callback_waktuid("BARANG_TGL_REG")');

    or

    $this->datatables->edit_column('BARANG_TGL_REG', '$1','$this->waktuid("BARANG_TGL_REG")');

    the result is same..

    i think call_user_func_array in exec_replace function datatables.php file only identifier built in php function like trim, substr, etc..

    please help me how parsing local function from edit_column.


    Thanks, sorry my english is bad


    i got temporary solution until i got another solutions from here

    i copied waktuid function to datatables.php, then i call edit_column like this

    $this->datatables->edit_column('BARANG_TGL_REG', '$1','call_user_func_array("waktuid", BARANG_TGL_REG)');

    after that, i modified function exec_replace in datatables.php

    $replace_string = @call_user_func_array($func, $args);
    //var_dump($args);
    if($args[0] == "waktuid"){
     $replace_string = $this->waktuid($args[1]);
    }

    and it work..but i’m still waiting the best solutions from here..

    Thanks..

  • #431 / Sep 04, 2013 3:08am

    ηυмвєяσηє

    109 posts

    Hi afirdaus,

    Put that function into a helper file. Then load the helper file before the datatables library.

  • #432 / Sep 20, 2013 5:07am

    stefenw

    6 posts

    hello

    i am newbie in codeigniter and datatables , i need your help.

    i use latest ignited datatables with mssql database,

    every function is work for me except paging,

    first display it work fine with 10 display record,when i click page 2 its display 1-20 records,page 3 display 1-30 records.

    please help

    paging in datatables

    private function get_paging() {
            $iStart = $this->ci->input->post('iDisplayStart');
            $iLength = $this->ci->input->post('iDisplayLength');
    
            if ($iLength != '' && $iLength != '-1')
                $this->ci->db->limit($iLength, ($iStart) ? $iStart : 0);
        }

    initialization

    var oTable = $('#big_table').dataTable( {
      "bProcessing": true,
      "bServerSide": true,
      "sAjaxSource": '<?php echo base_url(); ?>index.php/subscriber/datatable',
                    "bJQueryUI": true,
                    "sPaginationType": "full_numbers",
                    "iDisplayStart ":20,
                    "oLanguage": {
                "sProcessing": "<?php echo base_url(); ?>assets/images/ajax-loader_dark.gif"
            },  
            "fnInitComplete": function() {
                    //oTable.fnAdjustColumnSizing();
             },
                    'fnServerData': function(sSource, aoData, fnCallback)
                {
                  $.ajax
                  ({
                    'dataType': 'json',
                    'type'    : 'POST',
                    'url'     : sSource,
                    'data'    : aoData,
                    'success' : fnCallback
                  });
                }
     } );


    controller

    function datatable()
        {
            $this->datatables->select('nik,nama,nickname')
            ->from('dbo.tb_mt_PIM');
            
            echo $this->datatables->generate();
        }
  • #433 / Sep 27, 2013 9:13am

    kringon

    1 posts

    I am trying to get DataTables to work server side. My program is running upwards of 200.000 elements that i need to filter out now, and IE is having a hard time rendering a table with that many elements.

    So far i have setup the following:

    JS:

    var testTable = $('#example').dataTable( {
      "bProcessing": true,
      "bServerSide": true,
      "sAjaxSource": "<?php echo base_url(); ?>search/serverSide"
     } );

    Controller:

    function serverSide(){
         
       $this->load->library('datatables');
            
            $this->datatables->select('id, title,description, created, updated');
            $this->datatables->from('tickets');
               
            
            echo $this->datatables->generate();
                          
           
        }

    HTML:

    <table id="example">
                        <thead>
                            <tr>
                                <th>id</th>
                                <th>title</th>
                                    <th>description</th>
                                    <th>created</th>
                                    <th>updated</th>
                             
                            </tr>
                        </thead>
                        <tbody> 
                            <tr>
                                <td colspan="3">Loading Data</td>
                            </tr>
                        </tbody>
                    </table>


    This works fine with bServerSide:false, but i want this to work with bServerSide:true.

    How can i get this to work?

    I assume that with bServerSide:false it only outputs directly the ajax-response i am getting at myURL/search/serverSide

    Any ideas? Do i need to implement any other libraries

  • #434 / Oct 01, 2013 1:21am

    bundanarty

    1 posts

    I follow tutorial igneted datatables https://github.com/IgnitedDatatables/Ignited-Datatables/wiki/Function-Reference

    function datatables(){
        $this->datatables
                ->select('TerminalID,AtmLocation,MaxNumOfBills1,MaxNumOfBills2')
                ->from('terminalset');
        header('Content-Type: application/json');
        echo $this->datatables->generate(); 
        }

    and I have trouble when i use stored procedures.. like this

    $this->db->query('proc_request "$parameter"');

    how to call store procedure sql server in Igneted Datatables?

    how do I add a query function in libraries datatables.php? https://github.com/IgnitedDatatables/Ignited-Datatables/blob/master/application/libraries/Datatables.php

     

  • #435 / Oct 04, 2013 7:23pm

    rogertcd

    2 posts

    Hi, I’m working with Ignited datatables and I have two custom columns, one of them is for options (Edit, delete); another is for add more information about the record, this information is extracted from another request to Data Base, I did it with a helper. However, when the final user write something in search field, the datatable doesn’t search in that custom column, my code is:

    CONTROLLER

    $this->datatables->select("ID_F,CODIGO,SUSCRIPCION,NUMERO,NOMBRE,INSTITUCION1,FECHA_INS,FECHA_UPD")
                        ->add_column('INSTITUCION 2', '<span>$1</span>','get_institucion(ID_F)')
                        ->add_column('OPCIONES', get_buttons('$1'),'ID_F')
                        ->from('LISTAR_CONVENIOS');
                    }
                }
                echo $this->datatables->generate();

    HELPER

    function get_institucion($id)
    {
        $CI =& get_instance();
        $instituciones='';
        $CI->load->model('Convenios');
        $registros=$CI->Convenios->m_listar_parte2($id);
        foreach($registros->result() as $registro){
            if($instituciones!='') $instituciones.=', '.$registro->INSTITUCION;
            else $instituciones=$registro->INSTITUCION;
        }   
        return $instituciones;
    }

    I would like datatable takes in count “INSTITUCION 2” column, when the final user wants to search, Could someone help me please?

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

ExpressionEngine News!

#eecms, #events, #releases