Certain rows must not be updated when using on_update callback

QuestionsCertain rows must not be updated when using on_update callback
Patricia Lawson asked 7 years ago

Sir,
My users add a record and status is set to 'ADD'.
Users are not allowed to edit a record when the status field = 'ADD', but otherwise, I would like to use the on_update callback.
I can check for the status in the callback function – can I then abort the automatic Edit?

Thanks in advance

12 Answers
Abu Ghufran answered 7 years ago

Hello,

This is doable with server side validation.
You can put this check in on_update.

Refer demos/editing/server-validation.php code sample.

Patricia Lawson answered 7 years ago

Thanks, Abu,
The sample you cite does not use true as the third argument. I do:
$e["on_update"] = array("update_customer", null, true);

In the function update_customer(), I discover that I must not allow the edit to proceed. Can I then cancel the edit?

I am trying to use phpGrid to do the Update in most (almost all) cases, and stop it only sometimes…

Abu Ghufran answered 7 years ago

Hi,

In function when you call, phpgrid_error()
e.g.
phpgrid_error("Client already exist in database");

Then it stops execution and show message on grid.

Patricia Lawson answered 7 years ago

Perfect, thanks.

Abu Ghufran answered 7 years ago

Hi,

By default grid assumes that first column is auto-generated (hence auto-inserted on insert query)
If you want to insert it from grid, you can set with listId:

$col["autoid"] = false;

Patricia Lawson answered 7 years ago

Abu,
Using this same technique, I call $e["on_insert"] = array("addCustomer", null, true);

In addCustomer(), I update a lot of default column values, and I assign a random value to ListID, which is my table key and the first column in my Select. (only operating on 1 table)

***ListID is never inserted in the table.***

This is what my array looks like as I exit addCustomer and have phpGrid continue the row addition:

13-Apr-2017 20:46:55 Europe/Berlin] Array
(
[ListID] => 764809223
[params] => Array
(
[FullName] => BDA Test4
[Contact] => pat
[Phone] => 0987654321
[Email] =>
[ShipAddress_Addr2] =>
[ShipAddress_Addr3] =>
[ShipAddress_City] =>
[ShipAddress_State] =>
[ShipAddress_PostalCode] =>
[Status] => ADD
[Name] => BDA Test4
[AccountNumber] => 493629115
[SalesRepRef_FullName] => joe staff
[CustomerTypeRef_FullName] => CREDITHOLD
[TermsRef_FullName] => Net 30
[isActive] => true
[CustomField1] => 0%
)

)
Any ideas?

Patricia Lawson answered 7 years ago

The definition of column ListID is:
$col = array();
$col["title"] = "ListID";
$col["name"] = "ListID";
$col["show"] = array("list"=>false,"add"=>false, "edit"=>false, "view"=>false);
$col["editable"] = true;
$col["export"] = false;
$cols[] = $col;

Patricia Lawson answered 7 years ago

Thanks, Abu: this works!

Now I have a few other issues wrt to errors:
1. php_error_log shows: PHP Notice: Undefined index: xyz for all of the columns I am adding.

2. If I simply refresh my grid I see: PHP Warning: Invalid argument supplied for foreach() in C:xampphtdocsbecustomfileslibincjqgrid_dist.php on line 5527

There are no errors/warnings when I edit a column.

I realize one can turn reporting off, but not sure that is a good approach.

Thanks in advance.

Abu Ghufran answered 7 years ago

About notices, so far (turning off reporting) that's the solution we use. And optimization is in our todos.
Regarding warning, if you can send exact line or email me whole jqgrid_dist.php … i can check. It should not be displayed.

Patricia Lawson answered 7 years ago

Followed up with email and sent you the jqgrid_dist.php

Abu Ghufran answered 7 years ago

Fixed in last emailed lib.

Patricia Lawson answered 7 years ago

The Warnings have gone away.

Thanks, Abu!

Your Answer

2 + 3 =

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?