[eluser]johnwbaxter[/eluser]
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!
[eluser]ηυмвєяσηє[/eluser]
thanks,
v0.4.1beta
changes:
*added method 'edit_column',
*added support for callback functions in replacements (usable in both add_column and edit_column)
Code: 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="' . base_url() . 'admin/profiles/edit/$1">Edit</a>', 'tbl_profile.id')
->add_column('delete', '<a href="' . base_url() . 'admin/profiles/delete/$1">Del</a>', 'tbl_profile.id')
->edit_column('tbl_profile.name' , '<a href="' . base_url() . 'admin/profiles/edit/$1">$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
[eluser]johnwbaxter[/eluser]
Okay, great, i'll give this a go today. Nice work.
[eluser]ηυмвєяσηє[/eluser]
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)
Code: <?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.
[eluser]ηυмвєяσηє[/eluser]
latest usages in v.0.4.3 beta:
simple usage :
Code: 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:
Code: 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:
Code: 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="' . base_url() . 'admin/profiles/edit/$1">Edit</a>', 'id')
->add_column('delete', '<a href="' . base_url() . 'admin/profiles/delete/$1">Del</a>', 'id')
->edit_column('username' , '<a href="' . base_url() . 'admin/profiles/edit/$1">$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
[eluser]cryogenix[/eluser]
pushed the new codes to git already. wiki is being updated.
meanwhile, refer to yusuf's post #154 for usage guides...
[eluser]johnwbaxter[/eluser]
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?
Code: ->edit_column('timestamp', '$1', "callback_date(d-m-Y H:i|)");
The second parameter needs to be the timestamp itself.
[eluser]ηυмвєяσηє[/eluser]
Code: ->edit_column('timestamp', '$1', "callback_date(d-m-Y H:i|timestamp)");
thats it ^^
[eluser]johnwbaxter[/eluser]
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!
[eluser]ηυмвєяσηє[/eluser]
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 |1305927001)
so this may work..
Code: $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.
|