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]
  • #151 / May 23, 2011 5:53am

    johnwbaxter

    651 posts

    Hey Yusuf, that’s real nice. I was thinking about this over the weekend and that is exactly how i would have implemented it. I think this functionality is required. It needs to be as flexible as possible.

    Great work!

  • #152 / May 23, 2011 2:38pm

    ηυмвєяσηє

    109 posts

    thanks,

    v0.4.1beta

    changes:
    *added method ‘edit_column’,
    *added support for callback functions in replacements (usable in both add_column and edit_column)

    function list_all()
        {
          $this->datatables
            ->select('id, name, email, 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('edit', '<a href="http://">Edit</a>', 'tbl_profile.id')
            ->add_column('delete', '<a href="http://">Del</a>', 'tbl_profile.id')
            ->edit_column('tbl_profile.name' , '<a href="http://">$2</a>', 'tbl_profile.id, tbl_profile.name') /// (make links)
            ->edit_column('tbl_profile.email' , '$1***@***', 'callback_substr(tbl_profile.email|0|4)'); // (show only the first 4 chars of emails)
    
          $data['result'] = $this->datatables->generate();
          $this->load->view('ajax', $data);
        }

     

     

    Regards,
    Yusuf

  • #153 / May 24, 2011 5:56am

    johnwbaxter

    651 posts

    Okay, great, i’ll give this a go today. Nice work.

  • #154 / May 25, 2011 6:22pm

    ηυмвєяσηє

    109 posts

    hello guys again.

    I know it is out of topic,One of my friends asked and I’ve made a native php version of the library. http://bit.ly/j4zyMP
    Someone else can find it useful 😊

    usage: (create a file that you are gonna call: ajax.php)

    <?php
    require_once('Datatables.php');
    $datatables = new Datatables;
    
    $config = array( 
       'user' => 'root',
       'password' => '',
       'db' => '',
       'server' => 'localhost' );
    
    $datatables->select('id, username, email, activated')
        ->from('users')
        ->using('id');
    
    echo $datatables->generate($config);
    ?>

    Usage is very similar. Again it is for native php.
    Regards.

  • #155 / May 29, 2011 9:05am

    ηυмвєяσηє

    109 posts

    latest usages in v.0.4.3 beta:

    simple usage :

    function list_all()
        {
          $this->datatables
            ->select('id, name as username, email, age')
            ->from('tbl_profile');
    
          $data['result'] = $this->datatables->generate();
          $this->load->view('ajax', $data);
        }

    usage with joins:

    function list_all()
        {
          $this->datatables
            ->select('id, name as username, email, age')
            ->from('tbl_profile')
            ->join('tbl_local', 'tbl_profile.local_id = tbl_local.id', 'left')
            ->select('country');
    
          $data['result'] = $this->datatables->generate();
          $this->load->view('ajax', $data);
        }

    sample contains all the features:

    function list_all()
        {
          $this->datatables
            ->select('id, name as username, email, age')
            ->from('tbl_profile')
            ->join('tbl_local', 'tbl_profile.local_id = tbl_local.id')
            ->select('country')      
            ->join('tbl_states', 'tbl_profile.state_id = tbl_states.id')
            ->select('state')
            ->add_column('edit', '<a href="http://">Edit</a>', 'id')
            ->add_column('delete', '<a href="http://">Del</a>', 'id')
            ->edit_column('username' , '<a href="http://">$2</a>', 'id, username')
            ->edit_column('email' , '$1***@***', 'callback_substr(email|0|4)');
    
          $data['result'] = $this->datatables->generate();
          $this->load->view('ajax', $data);
        }

    edit : removed links, v0.5 will be released soon..

    Regards,
    Yusuf

  • #156 / May 30, 2011 10:39pm

    cryogenix

    90 posts

    pushed the new codes to git already. wiki is being updated.

    meanwhile, refer to yusuf’s post #154 for usage guides…

  • #157 / Jun 02, 2011 12:31pm

    johnwbaxter

    651 posts

    Hey Yusuf, sorry about the delay in testing this bu i had a project come up that i had to run off to!

    How would you go about handling this?

    ->edit_column('timestamp', '$1', "callback_date(d-m-Y H:i|)");

    The second parameter needs to be the timestamp itself.

  • #158 / Jun 02, 2011 2:05pm

    ηυмвєяσηє

    109 posts

    ->edit_column('timestamp', '$1', "callback_date(d-m-Y H:i|timestamp)");

    thats it ^^

  • #159 / Jun 03, 2011 9:36am

    johnwbaxter

    651 posts

    That doesn’t seem to work for me, it just gives me 01-01-1970 01:00 for all the dates. I had tried that but it didn’t work out which was why i thought i must be missing something!

  • #160 / Jun 03, 2011 11:52am

    ηυмвєяσηє

    109 posts

    depending on http://php.net/manual/en/function.date.php, date function needs second parameter to be integer.

    it should be in this format : callback_date(M-d-Y H:i:s|1305927001)

    so this may work..

    $this->load->helper('date');
    
    ..
    ..
    
    ->edit_column('timestamp', '$1', "callback_mysql_to_unix(timestamp)")
    ->edit_column('timestamp', '$1', "callback_date(d-m-Y H:i|timestamp)")

    btw, i’ve updated git.

  • #161 / Jun 03, 2011 12:14pm

    johnwbaxter

    651 posts

    Wow, that’s the strangest thing. I haven’t changed a thing and now it’s working. That’s very very odd.

    Thanks for the response though!

  • #162 / Jun 08, 2011 3:42am

    LoganPHP

    15 posts

    My server code is

    $this->datatables
                ->select("tps.id,tp1.image,tps.title,IF(tps.status=1,'E','D') as st,tps.views",FALSE)
                ->from('tb_photos AS tps')
                ->join('(SELECT tp.photos_id, MAX( tp.id ) AS lastid FROM tb_photo AS tp GROUP BY tp.photos_id) AS lastphoto', 'tps.id = lastphoto.photos_id','left')
                ->join('tb_photo as tp1', 'lastphoto.lastid=tp1.id','left')
                ->edit_column('tp1.image', 'thumb)link', 'tp1.image')
                ->add_column('comments', 'comment link', 'tb_videos.id')
                ->add_column('action', 'action_link', 'tb_videos.id');

    my client side code is

    'bProcessing'    : false,
                          'bServerSide'    : true,
                          'bAutoWidth'     : false,
                          'sAjaxSource'    : '<?php echo site_url('backend/photos/listener');?>',
                          'aoColumns' : [
                                { 'sName': 'tps.id','bVisible': false},
                                { 'sName': 'tp1.image',"bSearchable": false},
                                { 'sName': 'tps.title'},
                                { 'sName': 'st',"bSearchable": false},
                                { 'sName': 'tps.views',"bSearchable": false},
                                { 'sName': 'comments',"bSearchable": false},
                                { 'sName': 'action',"bSearchable": false}
                            ],
                           'fnServerData': function(sSource, aoData, fnCallback)
                          {
                            $.ajax
                            ({
                              'dataType': 'json',
                              'type'    : 'POST',
                              'url'     : sSource,
                              'data'    : aoData,
                              'success' : fnCallback
                            });
                          },
                            sDom: '<"block-controls"<"controls-buttons"p>>rti<"block-footer clearfix"lf>',
                            fnDrawCallback: function()
                            {
                                this.parent().applyTemplateSetup();
                            },
                            fnInitComplete: function()
                            {
                                this.parent().applyTemplateSetup();
                            }

    My problem is here IF(tps.status=1,‘E’,‘D’) as st.

    If i use AS in main SELECT query it doesn’t output properly.

    Whenever i use AS,I’m facing this problem.How can i solve this problem?

    Thanks in advance,
    Logan

  • #163 / Jun 08, 2011 7:12am

    ηυмвєяσηє

    109 posts

    Hey,

    The library supports basic sql queries atm. Never tried subqueries with it before.

    I’ve made some changes (0.5.2beta):
    - fixed select method, it’ll select queries like “IF(tps.status=1,‘E’,‘D’) as st” properly.
    - changed callback parameter style, in order to use comma insted of ‘|’.
      for example : callback_substr(email,0,4)
    - unset_column($column) method has been added.
    - *fixed an issue on filtering. (when using ‘as’ in select method, sql was giving error.)

    Lib: http://bit.ly/l4HKzG

    What do you think ?

    couldnt test it very well, i hope you do.

    Regards,
    Yusuf

    [*Updated: 15.06.2011]

  • #164 / Jun 09, 2011 4:49am

    LoganPHP

    15 posts

    Our library supports sub-queries very well.

    Still now i have problem with ....IF(tps.status=1,‘E’,‘D’) as st…. main select query.

    json return properly,only output collapsed.

    How can i solve this?

  • #165 / Jun 09, 2011 5:09am

    ηυмвєяσηє

    109 posts

    ive tried “IF(tps.status=1,‘E’,‘D’) as st ” seems no problem, its working.

    can you show me the output or any error ? And did you change anything on server side or its still same ?

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

ExpressionEngine News!

#eecms, #events, #releases