[英]Auto calculation grocery crud
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. 例如:我有一些列a,b和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.
我已经使用过callback_column函数,但现在可以正常使用,callback_column仅在视图页面上显示结果,并且无法自动保存到数据库。 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'); $ crud-> change_field_type('your_field','invisible');
API document can help: http://www.grocerycrud.com/documentation/options_functions API文档可以提供帮助: 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. 您可以使用javascript添加新元素并处理自动计算。 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.
您需要确保该值将随var_dump的发布请求一起提供,该值将在回调:callback_before_insert或call_back_before_update中传递$ post_data的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.