Update table with predefined field value

QuestionsUpdate table with predefined field value
Jose asked 8 years ago

I have an editable table and when the user edits the table, the field 'usernumber' must be also updated with his number ID.
The field 'usernumber' is updated automatically without intervention from user.

$col["editoptions"] = array("defaultValue" => "Default Company");

In this example is possible when add new row, but does not work in update and the user can change the value before submit.

My need is something like this example

$col = array();
$col["title"] = "UserNumber";
$col["name"] = "usernumber";
$col["editable"] = false;
$col["editoptions"] = array("defaultValue" => $usernumber);
$cols[] = $col;

Thanks

7 Answers
Abu Ghufran answered 8 years ago

You can use afterShowForm event of edit form and reset the field value using JS as required.

e.g.
$opt["edit_options"]["afterShowForm"] = 'function () { jQuery("#usernumber").val('.$username.'); }';

$g->set_options($opt);

You can inspect the field id.using firebug and use jquery functions to disable / enable desired field.
To know jquery selector:

http://easycaptures.com/fs/uploaded/1017/9892108434.png
http://easycaptures.com/fs/uploaded/1017/9617668813.png

Jose answered 8 years ago

$col = array();
$col["title"] = "UserNumber";
$col["name"] = "usernumber";
$col["width"] = "45";
$col["align"] = "left";
$opt["edit_options"]["afterShowForm"] = '10';
$cols[] = $col;

Is this a valid option for my request?

Abu Ghufran answered 8 years ago

Please send complete code, i'll the suggest the changes.
You can email at [email protected]

Jose answered 8 years ago

Using the demo included with the framework (demos/editing/index.php).
With that file is possible to edit the demo DB, on ClientId, Name, Gender and Company.
My question is:
How can I change the demo for user insert/update on ClientId, Name and Gender and not Company.
But everytime a row is inserted/updated, the field Company is also inserted/updated but with a value received by HTTP POST from a previous page and not by user action.

Jose answered 8 years ago

One pratical use for my request is for example:
I have a DB that can be edited by users.
All the users are authenticated with name and password.
The user name is passed to the page by POST or SESSION
When a user makes a change to the DB is necessary to record also is name, so
is possible to check who is responsible for the changes.
For security reasons the name can't be inserted manually. It must be inserted
internally by the code.
The user name is passed by session variables, so is not editable by the user.
Thank you!

Jose answered 8 years ago

PS: The field 'name' or 'Company' are not necessary to be visible on the grid.
They can never appear to user.

Abu Ghufran answered 8 years ago

You can have default values inserted by code using on_insert event handler.
It is supported in full version (demos/editing/custom-events.php)

You can hide any column using column settings:
$col["hidden"] = true;
For further help, refer docs: http://www.phpgrid.org/docs/#Selecting_Specific_Columns

Your Answer

4 + 12 =

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?