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]
  • #376 / Oct 19, 2012 5:44am

    ninjayan

    72 posts

    Totally new to this. I want to use on the application I am developing. This is a great library. Can someone give me a working example? Or just a tutorial link? I also want to add 1 column at the end for actions(select/delete) thanks

  • #377 / Oct 19, 2012 11:24am

    ZaLiTHkA

    29 posts

    Totally new to this. I want to use on the application I am developing. This is a great library. Can someone give me a working example? Or just a tutorial link? I also want to add 1 column at the end for actions(select/delete) thanks

    This CI library is built around the ‘server side’ data source as seen in this example. It doesn’t include DataTables itself. 😊 What you’re asking about is more a DT related question, to which I’m sure you’ll find all the info you need in documentation on DataTables.net.

  • #378 / Oct 20, 2012 2:23am

    ninjayan

    72 posts

    I have datatables working on plain php but now i want to use it in codeigniter. So I came over here and found this. If this is not what I’m looking for, can you give me links/tutorials/samples how to implement datatables in codeigniter?

  • #379 / Oct 20, 2012 8:24am

    ninjayan

    72 posts

    I have this current code.

    $this->load->library('datatables');
      $this->datatables
        ->select("username")
        ->select("CONCAT(salutation, '. ', first_name, ' ', middle_initial, '. ', last_name) as full_name", FALSE)
        ->select("office, position, email, privilege, datetime_registered")
        ->where("username !=", $this->session->userdata('username'))
        ->from("users")
        ->add_column('view', '<a href="http://">AA</a>');
      echo $this->datatables->generate();

    I want to add a column at the end for ‘Actions’
    add_coumn is not working

  • #380 / Oct 20, 2012 2:42pm

    ZaLiTHkA

    29 posts

    I have this current code.

    $this->load->library('datatables');
      $this->datatables
        ->select("username")
        ->select("CONCAT(salutation, '. ', first_name, ' ', middle_initial, '. ', last_name) as full_name", FALSE)
        ->select("office, position, email, privilege, datetime_registered")
        ->where("username !=", $this->session->userdata('username'))
        ->from("users")
        ->add_column('view', '<a href="http://">AA</a>');
      echo $this->datatables->generate();

    I want to add a column at the end for ‘Actions’
    add_coumn is not working

    Ah, I see what you mean now. Sorry, I misunderstood your first post.. My mistake. 😊

    Just to confirm, is this code in your controller or your model? Is the data getting through if you try without the add_column() method in the chain?

    If I remember correctly, when I tried this I only got it to work after using print() at the end of the $this->datatables() chain. Here’s the relevant code from a recent project I worked on:

    // MY_Controller
    function get_list() {
     $this->load->model('my_model');
     $this->my_model->get_list();
    }
    
    // MY_Model
    public function get_list() {
     $this->datatables->select('
      Table.Col1,
      Table.Col2,
      Table.Col3
     ');
     $this->datatables->from('Table');
     
     print($this->datatables->generate());
    }

    In this case, I set the AJAX source in my DT initialization to a url generated by:

    echo(base_url('my_controller/get_list'));

    Not sure if there’s a better way to do this, but this worked for me. Just a thought, but maybe try use print() instead of echo() on your generate() line.

  • #381 / Oct 20, 2012 10:38pm

    ninjayan

    72 posts

    Thanks for replying.
    My code is only at the controller. I haven’t tried yet to put it on my model.

  • #382 / Oct 20, 2012 11:04pm

    ninjayan

    72 posts

    Ok, I think I have to show you the codes.

    controller

    public function get_active_users() {
      $this->load->library('datatables');
      $this->datatables
        ->select("username")
        ->select("CONCAT(salutation, '. ', first_name, ' ', middle_initial, '. ', last_name) as full_name", FALSE)
        ->select("office, position, email, privilege, datetime_registered")
        ->where("username !=", $this->session->userdata('username'))
        ->from("users")
        ->add_column("view", "<a>AA</a>");
      echo $this->datatables->generate();
     }

    view:

    [removed]
     $(document).ready(function() {
      $('#users_table').dataTable({
       //"sScrollX": "100%",
       //"sScrollXInner": "100%",
       "sPaginationType": "full_numbers",
       "bProcessing": true,
       "bServerSide": true,
       "bJQueryUI": true,
       "bDeferRender": true,
       "sAjaxSource": "<?php echo base_url(); ?>/users/get_active_users",
       "sServerMethod": "POST"
      });
     });
     [removed]
    
    <thead>
          <tr>
           <th class="width70 text-center">Username</th>
           <th class="text-center">Full Name</th>
           <th class="text-center">Office</th>
           <th class="text-center">Position</th>
           <th class="text-center">Email</th>
           <th class="width60 text-center">Privilege</th>
           <th class="width160 text-center">Date Registered</th>
          </tr>
         </thead>
         <tbody>
          <tr>
           <td colspan="7" class="dataTables_empty">Loading data from server</td>
          </tr>
         </tbody>

    I want to add a column Action after the ‘Date Registered’. Content of it will be icon disable user, promote/remove as admin.

  • #383 / Oct 21, 2012 5:40am

    ZaLiTHkA

    29 posts

    I want to add a column Action after the ‘Date Registered’. Content of it will be icon disable user, promote/remove as admin.

    I suspect the biggest issue here is the fact that the number of columns between your data source (in your controller) and the number of columns in your end table (in your view), do not match. You’re trying to put data for 8 columns into a 7 column table. Out of curiosity, have you tried adding an extra column to your HTML table in your view? Sometimes the simplest solution works out best in the end.

    Unfortunately though, DataTables itself doesn’t support dynamically adding columns, this question has been asked many times on the DT forum in the past. Digging through these questions again this morning, I found a link to a tutorial that looks like it does exactly what you’re asking for [link].

    Otherwise, have you considered using something like the drill-down rows example, placing the ‘user specific functions’ in the row that shows up below the clicked row? This way, the data is added dynamically to the row before it’s displayed, and the row is destroyed after it’s hidden. It’s very easy to use and very efficient as well.

    This is giving me ideas for another project I’m working on now.. Time to go play. (:

  • #384 / Oct 21, 2012 6:17am

    ninjayan

    72 posts

    Thank you. I will try it.

  • #385 / Oct 21, 2012 10:06pm

    ninjayan

    72 posts

    Can I directly echo the username in the add_column? I want to put the username inside anchor tag

    $this->load->library('datatables');
      $this->datatables
        ->select("username")
        ->select("CONCAT(salutation, '. ', first_name, ' ', middle_initial, '. ', last_name) as full_name", FALSE)
        ->select("office, position, email, privilege")
        ->select("DATE_FORMAT(datetime_registered, '%b %d, %Y - %h-%i %p') as datetime_registered", FALSE)
        ->where("username !=", $this->session->userdata('username'))
        ->from("users")
        ->add_column("view", "<a>A</a>"); //HERE
      echo $this->datatables->generate();

    The first link is the same from what I’m looking for but I’m using ignited datatables.
    Sorry.

  • #386 / Oct 22, 2012 1:10am

    ninjayan

    72 posts

    How to use it with action column for example edit/delete etc.

    <tr>
    <td> id from db</td>
    <td> name from db </td>
    <td> Edit
    </tr>

    you can use petroz’s client side solution to create additional columns:

    I use a callback on the Datatables.net configuration to generate the table on the fly. Add `fnDrawCallback` to attach any javascript function/method to the generation process.

    Here is one for adding columns.

    Datatables.prototype.addDataColumn = function()
    {
    $("#datatable tr:gt(0)").append("<td>View Edit Delete</td>”);
    }

    or you can also modify the library where I commented:

    /*
      add additional columns here
      like adding a Delete Row control for example:
    
      $aaData[$row_key][] = '<a href="#">Delete Button</a>';
    */

    Can’t find this commented lines.

  • #387 / Oct 22, 2012 3:18am

    ninjayan

    72 posts

    Okay. so I guess this will be my last question for this.

    ->add_column("Action",
            "<form id='modify_form' action='modify_user/$1'>
            <button class='modify-btn' title='Modify'>
            ../assets/images/edit.png
            </button>
            </form>",
            "username");

    Form submit goes to ‘modify_user’ function. Now I want to store the username to a variable and I will do compare. How will I do that?

  • #388 / Oct 22, 2012 5:46am

    ninjayan

    72 posts

    Okay so I just answered my question. 😊
    Thanks again to those who gave inputs.

  • #389 / Oct 23, 2012 2:21am

    harshitha

    12 posts

    I got this error, why is this?

    A Database Error Occurred
    
    Error Number: 1096
    
    No tables used
    
    SELECT * LIMIT 100
    
    Filename: C:\server\www\bigpmc\system\database\DB_driver.php
    
    Line Number: 330
  • #390 / Oct 23, 2012 3:17am

    ninjayan

    72 posts

    check your database configuration. As said on the error, ‘no tables used’

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

ExpressionEngine News!

#eecms, #events, #releases