[eluser]lordoffriends[/eluser]
Everything is working now.
[eluser]cryogenix[/eluser]
made a small update which may be great news to some.
added foreign charset support for generating results.
so these are now possible:
Code: //generate with default utf-8 encoding
$this->datatables->generate();
//generate with latin-1 character support
$this->datatables->generate('ISO-8859-1');
i hope some of you may find this useful (as i did at work today).
[eluser]jtrainaldi[/eluser]
I was wondering if I can pass a controller function into the add_column parameter. The function called queries a separate database and prints out a string based on whether there is data in the table or not.
Code: $this->datatables
->select('id, employee_name, submitted_date')
->from('wc_table')
->add_column('related_info', $this->printRelateInfo($id), 'id')
;
function printRelateInfo($id){
$str = '';
//Get the employee data
$employee_data = $this->employee_model->getEmployeeData($id);
if(sizeof($employee_data)==0):
$str .= '<a- href="#" class="disabled-link"><img src="form.png" alt="form icon" /></a>';
else :
$str .= '<a- href="viewInfo/$employee_data[0] ['id']"><img src="form.png" alt="form icon" /></a>';
endif;
echo $str;
}
[eluser]cryogenix[/eluser]
don't echo it in the function. return it instead:
Code: $this->datatables
->select('id, employee_name, submitted_date')
->from('wc_table')
->add_column('related_info', $this->printRelateInfo($id), 'id');
function printRelateInfo($id)
{
$str = '';
//Get the employee data
$employee_data = $this->employee_model->getEmployeeData($id);
if(sizeof($employee_data)==0):
$str .= '<a href="#" class="disabled-link"><img src="form.png" alt="form icon" /></a>';
else:
$str .= '<a href="viewInfo/$employee_data[0]['id']"><img src="form.png" alt="form icon" /></a>';
endif;
return $str;
}
[eluser]Derek Nutile[/eluser]
In your example above, how does the printRelateInfo function know what the variable $id is? Shouldn't it be more like a back reference like the code below? I can't get that to work either though, so any help would be appreciated.
Code: ->add_column('related_info', $this->printRelateInfo('$1'), 'id');
[eluser]cryogenix[/eluser]
i just copied your code and didn't notice that...
my point was about returning the result instead of an echo.
adjust code as you see fit =)
[eluser]Unknown[/eluser]
Hey there, thanks a lot for this plugin, very useful but, like the last posts, I'm trying to add a function when editing/adding a column and it fails miserably, I only obtain "no" in every rows, could you help me a bit ?
Code: function userlist()
{
$this->load->library('datatables');
$this->datatables
->select("login, email, activation")
->from('users')
->edit_column('activation', $this->show_activation_link('$1', '$2'), 'activation, login');
echo $this->datatables->generate();
}
private function show_activation_link($status, $user)
{
if($status == 0)
{
return "no";
}
elseif($status == 1)
{
return "yes";
}
}
[eluser]Derek Nutile[/eluser]
My method uses active record. Here's a test method:
Code: function datatable_test ()
{
$query = $this->db->select('state_name');
$query = $this->db->get('states');
return = "Some output ...";
}
When I call this method with the Datatables library, like this:
Code: $this->datatables
->select('id, member_id, user_name, state')
->edit_column('state', $this->customer_model->datatable_test('$1'), 'id')
->from('orders');
echo $this->datatables->generate();
The result is a database error on the JSON page like this. Notice it has combined the fields from the datatables SQL with the datatable_test method:
Quote:Unknown column 'state_name' in 'field list'
SELECT id, member_id, user_name, state_name FROM (states) WHERE `statecd` = 'OR'
I assume this is because the library creates it's own CI object, but maybe you can clarify.
Note that I am making this simple. Of course my method doesn't just get the state for a user or I would create a JOIN. Instead, my method iterates through several stages to get an order status based on many variables.
[eluser]ηυмвєяσηє[/eluser]
First, you can not use 'edit_column' like :
Code: ->edit_column('state', $this->customer_model->datatable_test('$1'), 'id')
The second parameter must be a string. it is not possible to use functions in a controller in order to use '$1' value. You need to use a helper function instead of that and you need to use that as a callback function.
example of using a helper:
1. Create a helper file in your helper directory (datatables_helper.php)
2. Load your helper (datatables_helper.php) in your ajax listener.
Code: function listener()
{
$this->load->helper("Datatables"); // create datatables_helper.php in helpers folder
$this->load->library("Datatables");
$this->datatables
->select('id, name, email, age, status')
->from('tbl_profile')
->edit_column('name', '$1', 'strtolower(name)') // php functions
->edit_column('email', '$1', 'customfunction(id, email, status)'); //custom functions in your helper..
$data['result'] = $this->datatables->generate();
$this->load->view('ajax', $data);
}
3. Use SQL 'JOIN' statement as u can. Performance will be reduced, even if you did a function like below. Because, it runs a query at every row.
Code: function datatable_test ()
{
$query = $this->db->select('state_name');
$query = $this->db->get('states');
return = "Some output ...";
}
Regards,
Yusuf
[eluser]Derek Nutile[/eluser]
Exactly what I needed Yusuf, thanks!
|