sum colums

Questionssum colums
David asked 7 years ago

How can I insert the value of a+b into c?

$col = array();
$col["title"] = "LOG"; // caption of column
$col["name"] = "a"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["width"] = "200";
$col["align"] = "center";
$col["editable"] = FALSE;
$col["hidden"] = False;
$col["search"] = true;
$cols[] = $col;

$col = array();
$col["title"] = "LOG"; // caption of column
$col["name"] = "b"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["width"] = "200";
$col["align"] = "center";
$col["editable"] = FALSE;
$col["hidden"] = False;
$col["search"] = true;
$cols[] = $col;

$col = array();
$col["title"] = "LOG"; // caption of column
$col["name"] = "c"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["width"] = "200";
$col["align"] = "center";
$col["editable"] = FALSE;
$col["hidden"] = False;
$col["search"] = true;
$cols[] = $col;

1 Answers
Abu Ghufran answered 7 years ago

If your fields are editable, you can follow this faq:
http://www.phpgrid.org/faqs/#80

As in your code, these are editable=>false, so you can update value of 'c' on backend using on_insert / on_update callback function.
$e["on_update"] = array("update_field", null, true);
$e["on_insert"] = array("update_field", null, true);
$g->set_events($e);

function update_field($data)
{
$data["params"]["c"] = $data["params"]["a"] + $data["params"]["b"]
}

Here what ever value of 'a' & 'b' are posted back they will be summed and used in sql query.

Your Answer

17 + 13 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?