Welcome Guest, Not a member yet? Register   Sign In
Ignited DataTables

[eluser]Toby Gabler[/eluser]
Hi there,
great peace of code. Thanks for sharing it.

I wonder whether i'm able to output conditions like:

Code:
{{if pool_active == 1 }}
    <td align="center"><a id="0" class="activeBtn" href="${activeLink}"><span class="ui-icon ui-icon-check">1</span></a></td>
{{else}}
    <td align="center"><a id="1" class="activeBtn" href="${activeLink}"><span class="ui-icon ui-icon-closethick">0</span></a></td>
{{/if}}

or something like this.

Thanks for your help,
Toby

[eluser]Toby Gabler[/eluser]
Best questions are questions which i will be able to answer myself :-)

Code:
var activated=new Array("<font color=#990000>Inactive</font>","<font color=#009933>Active</font>");

{ "sName": "activated", "fnRender": function (oObj){return activated[oObj.aData[4]];} },

where aData[4] holds 0 or 1 ...

[eluser]cryogenix[/eluser]
well thank you for that. i can use that on my own implementations as well Big Grin

[eluser]Toby Gabler[/eluser]
I've found a more suitable solution.

Code:
$(document).ready(function (){          
    $('#usertable').dataTable({
        'fnRowCallback': function( nRow, aData, iDisplayIndex ) {

                $('td:eq(0)', nRow).html( '<a class="updateBtn" href="/promotion/updatePool/'+aData[0]+'"><span class="ui-icon ui-icon-wrench"></span></a>' );
                $('td:eq(1)', nRow).html( '<a class="deleteBtn" href="/promotion/deletePool/'+aData[1]+'"><span class="ui-icon ui-icon-trash"></span></a>' );

                if ( aData[6] == '1' )
                {
                    $('td:eq(6)', nRow).html( '<a class="activeBtn" href="'+aData[6]+'"><span class="ui-icon ui-icon-check">1</span></a>' );
                }

                else
                {
                    $('td:eq(6)', nRow).html( '<a class="activeBtn" href="'+aData[6]+'"><span class="ui-icon ui-icon-closethick">0</span></a>' );
                }
                    
                
            return nRow;
              },
.....

[eluser]cryogenix[/eluser]
[quote author="Pegasus275" date="1304562494"]With this you can select more columns and display only what you need. In custom column you can use columns that you are not want to display.

for example

$joins['meta']['columns'] = array('first_name','last_name','id as meta_id');

$custom_columns['delete'] = array('user_id :$1 group_id: $2', array('id','group_id'));

This is nice library but it be better to write something like

$this->datatable->join...
$this->datatable->custom_filed('edit','<a href="">$1</a>',array('id'));
$this->datatable->where('user.id'=1)->get('users')->json();

something like thatBig Grin[/quote]

wish granted! currently testing tentative git updates with support for method chaining... the syntax will be different but will be alot easier... i'm done with code cleanup so all that's left is to revise the wiki for usage instructions... kudos to yusuf on this one! ^_^b

here's the unpushed code: http://pastebin.com/V5ptZBQ8
and a usage example:

Code:
function list_all()
    {
      $this->datatables
        ->select('id, name, age')
        ->from('tbl_profile')
        ->using('id')
        ->join('tbl_local', 'country', 'tbl_profile.local_id = tbl_local.id')
        ->join('tbl_states', 'state', 'tbl_profile.state_id = tbl_states.id')
        ->add_column('view', '<a href="' . base_url() . 'admin/profiles/view/$1"><img src="' . base_url() . 'assets/images/admin/vcard.png" alt="View" title="View" /></a>', 'tbl_profile.id')
        ->add_column('edit', '<a href="' . base_url() . 'admin/profiles/edit/$1"><img src="' . base_url() . 'assets/images/admin/vcard_edit.png" alt="Edit" title="Edit" /></a>', 'tbl_profile.id')
        ->add_column('delete', '<a href="' . base_url() . 'admin/profiles/delete/$1"><img src="' . base_url() . 'assets/images/admin/vcard_delete.png" alt="Delete" title="Delete" /></a>', 'tbl_profile.id');

      $data['result'] = $this->datatables->generate();
      $this->load->view('ajax', $data);
    }

[eluser]ηυмвєяσηє[/eluser]
we would love to hear your feedbacks..

another sample of basic usage.

Code:
// old version
   function list()
    {
      $table = 'test';
      $columns = array('id', 'name', 'age', 'gender');
      $index = 'id';
      $this->load->library('Datatables');
      $data['result'] = $this->datatables->generate($table, $columns, $index);
      $this->load->view('ajax', $data);
    }

Code:
// new one, easy and more readable, you can use benefits of method chaining
   function list()
    {
      $this->load->library('Datatables');
      $data['result'] = $this->datatables
            ->select('id, name, age, gender')
            ->from('test')
            ->using('id')
            ->generate();
      $this->load->view('ajax', $data);
    }

Regards,
Yusuf

[eluser]cryogenix[/eluser]
ok version 0.4 is now available at our git repository along with an updated wiki for the new usage guide.

please do report any bugs that you may find here along with any feedbacks and/or suggestions.

thanks =)

[eluser]johnwbaxter[/eluser]
I'm having some serious issues with column ordering. Can anyone see where i'm going wrong here?

Controller:
Code:
function list_users_ajax()   {
      
        $table = 'users';
        $columns = array('id','email', 'created_on', 'authorised');
        $index = 'id';
        
        $joins['meta']['columns'] = array('first_name','last_name','company', 'licensee');  
        $joins['meta']['fk'] = 'users.id = meta.user_id';
        $options['joins'] = $joins;
        
        $custom_columns['users_name'] = array('<a href="user/profile/$1">$2 $3</a>', array('meta.user_id','meta.first_name', 'meta.last_name' ));
        $custom_columns['delete'] = array('<a href="auth/manual_edit_user/$1">Edit</a>', array('user.id'));
        $custom_columns['edit'] = array('<a href="auth/delete_user/$1">Delete</a>', array('user.id'));
        $options['custom_columns'] = $custom_columns;
      
        
        $this->load->library('Datatables');
        echo $this->datatables->generate($table, $columns, $index, $options);
    }

View:

Code:
$(document).ready(function()
  {
    $('#list_users').dataTable
    ({
      "bProcessing": true,
      'bServerSide'    : true,
      'bAutoWidth'     : false,
      'sPaginationType': 'full_numbers',
      'sAjaxSource'    : '&lt;?=base_url();?&gt;admin/list_users_ajax',
      'aoColumns'      :
      [

            { 'sName': 'users_name'},
            { 'sName': 'meta.company'},
            { 'sName': 'users.email' },
            { 'sName': 'meta.licensee' },
            { 'sName': 'users.created_on'},
            { 'sName': 'edit', 'bSortable' : false },
            { 'sName': 'delete','bSortable' : false }
        
      ],
      'fnServerData': function(sSource, aoData, fnCallback)
      {
        $.ajax
        ({
          'dataType': 'json',
          'type'    : 'POST',
          'url'     : sSource,
          'data'    : aoData,
          'success' : fnCallback
        });
      }
    });

<table border="0" cellpadding="4" cellspacing="0" id="list_users">
<thead>
<tr>
    <th>Users Name</th><th>Company</th><th>E-Mail</th><th>Licensee</th><th>Authorised</th><th>Date Created</th><th>Edit</th><th>Delete</th>
</tr>
</thead>
<tbody>                
                        <tr>
                            <td>loading...</td>
                        </tr>            
</tbody>
</table>

I can make it all work if i do it manually, but i'd like to use this library.

Can anyone see why i can't get the column ordering to work as i want it?

[eluser]ηυмвєяσηє[/eluser]
hi,

We have updated the library, i recommend you to download it .my example below is in our new syntax

About your problem. You need to add all columns to your javascript and html as much as you choose in your controller. You have selected total 11 columns. u should define 11 columns html and javascript.



Controller.
Code:
function list_users_ajax()
    {        
    $this->load->library("Datatables");
      $this->datatables
      ->select('id, email, created_on, authorised') // 4 columns here
      ->from('users')
      ->using('id')
      ->join('meta', 'first_name, last_name, company, licensee', 'users.id = meta.user_id') // 4 columns here
      ->add_column('users_name', '<a href="user/profile/$1">$2 $3</a>', 'users.id, meta.first_name, meta.last_name')
      ->add_column('edit', '<a href="auth/manual_edit_user/$1">Edit</a>', 'users.id')
      ->add_column('delete', '<a href="auth/delete_user/$1">Delete</a>', 'users.id');
      // 3 custom columns
      // we have total 11 columns .
      echo $this->datatables->generate();
    }
Javascript
Code:
'aoColumns'      :
      [
            { 'sName': 'users.id', 'bVisible' : false},
            { 'sName': 'meta.first_name', 'bVisible' : false},
            { 'sName': 'meta.last_name', 'bVisible' : false},                  
            { 'sName': 'users_name'},
            { 'sName': 'meta.company'},
            { 'sName': 'users.email' },
            { 'sName': 'meta.licensee' },
            { 'sName': 'users.authorised'},
            { 'sName': 'users.created_on'},
            { 'sName': 'edit', 'bSortable' : false },
            { 'sName': 'delete','bSortable' : false }
        
      ],
HTML
Code:
<table border="0" cellpadding="4" cellspacing="0" id="list_users">
<thead>
<tr>
    <th>User ID</th>
    <th>first name</th>
    <th>last name</th>
    <th>Users Name</th>
    <th>Company</th>
    <th>E-Mail</th>
    <th>Licensee</th>
    <th>Authorised</th>
    <th>Date Created</th>
    <th>Edit</th>
    <th>Delete</th>
</tr>
</thead>
<tbody>                
<tr>
    <td>loading...</td>
</tr>            
</tbody>
</table>

[eluser]johnwbaxter[/eluser]
Yes, i understand that i need to add all the columns, but the problem is that i don't want First Name, Last Name, ID to be in the rendered html table. I have another column "users_name" that is first_name.' '.last_name that i want instead. I also don't want to show the ID column, but have to include it in the select so i can use it in my delete and edit custom columns.

How can i hide those three columns in datatables? If i try doing the code below the grid itself throws a js error.
Any ideas?

Code:
{ "sName": "meta.last_name" ,"bVisible": false}




Theme © iAndrew 2016 - Forum software by © MyBB