I want to ask about function that can make auto calculation in grocery crud.
For example: I have some column a, b, and total_a_b. I have used function callback_column but its now work perfectly, callback_column just show the result on the view page and it can't auto save to database. What the function that can refer it? And whether there are a way to show that calculation automatic in field form?
This is my code:
public function try() {
$crud = new grocery_CRUD();
$crud->set_table('try');
$crud->columns('a', 'b', 'total');
$crud->callback_column('total', array($this, '_callback_column_total'));
$output = $crud->render();
$this->_example_output($output);
}
public function _callback_column_total ($value, $row) {
$a = $row->a;
$b = $row->b;
$total=$a + $b;
return $total;
}
it cant auto save to database. What the function that can refer it?
$crud->change_field_type('your_field', 'invisible');
API document can help: http://www.grocerycrud.com/documentation/options_functions
And whether there are a way to show that calculation automatic in field form?
You can use javascript to add new element and handle the auto calculation. And remember that there should be a hidden input will post with your post request to controller of grocery crud. You need to make sure that the value will come with post request by var_dump the value of $post_data in callbacks: callback_before_insert or call_back_before_update.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.