CodeIgniter Forums
[SOLVED] Ignited Datatables - button links don't work in add_column() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: External Resources (https://forum.codeigniter.com/forumdisplay.php?fid=7)
+--- Forum: Addins (https://forum.codeigniter.com/forumdisplay.php?fid=13)
+--- Thread: [SOLVED] Ignited Datatables - button links don't work in add_column() (/showthread.php?tid=63105)



[SOLVED] Ignited Datatables - button links don't work in add_column() - Lykos22 - 09-27-2015

I'd like some help please. I'm using Ignited Datatables library in order to display posts. My script at the begining was looking like this

PHP Code:
$this->datatables->select('posts.id, posts.title')->select('DATE_FORMAT(`date_published`, \'%d-%m-%Y\') AS `date_published`'false)
 
       ->from('posts')
 
       ->unset_column('id')
 
       ->add_column('Actions'btn_edit('admin/posts/edit/$1') . ' ' btn_delete('admin/posts/delete/$1'), 'id'); // this is the part I'm considering
 
      echo $this->datatables->generate(); 

so basicly in the add_column() I'm generating some button links to edit and delete posts and the urls of these buttons would look like this:

Code:
admin/posts/edit/1
admin/posts/delete/1

So far so good, but when I tryied to JOIN the post categories in the query

PHP Code:
$this->datatables->select('posts.id, posts.title')->select('DATE_FORMAT(`date_published`, \'%d-%m-%Y\') AS `date_published`'false)
 
       ->select('posts_categories.title as category')
 
       ->from('posts')
 
       ->join('posts_categories''posts.category_id = posts_categories.id''left')
 
       ->unset_column('id')
 
       ->add_column('Actions'btn_edit('admin/posts/edit/$1') . ' ' btn_delete('admin/posts/delete/$1'), 'id');
 
       echo $this->datatables->generate(); 

the urls of the button links broke and I get this, which goes to 404 page:

Code:
admin/posts/edit/id
admin/posts/delete/id

How can I fix this?


RE: Ignited Datatables - button links don't work in add_column() - Lykos22 - 09-28-2015

Eventually I 've found the solution to the problem. I'm gonna post it as an answer just in case anyone else has/had the same problem.

In select() statement I did this and worked properly:

PHP Code:
$this->datatables->select('posts.id AS pid, posts.title'

It seems that there was a conflict in the query in the primary keys of both tables, beacause I have set both as id (posts.id and posts_categories.id).

So back in the query when I set posts.id AS pid as an alias, this fixed my problem.