Default value in column

QuestionsDefault value in column
Daniele asked 12 years ago

Hi,
i need to assign default value to a column, if possible?

I have try this but not work

$id_user = $_SESSION['id_user'];
$col = array();
$col["title"] = "Id Utente";
$col["name"] = "id_user";
# $col["width"] = "300"; // not specifying width will expand to fill space
$col["sortable"] = false; // this column is not sortable
$col["search"] = false; // this column is not searchable
$col["editable"] = true;
$col["edittype"] = "text";
$col["editoptions"] = $id_user;
$col["hidden"] = false;
$cols[] = $col;

15 Answers
Abu Ghufran answered 12 years ago

To render as textbox with size 20, and initial value in textbox to 10

$col["editoptions"] = array("size"=>20, "value"=>'10');

… pasted from http://phpgrid.org/docs

Abu Ghufran answered 12 years ago

Yes, even this would work if you dont need size.
probably a typing mistake of missing '.

$col["editoptions"] = array("value"=>'$id_user');

Daniele answered 12 years ago

in my case the value is in the variable $ id_user, how should I do?

Daniele answered 12 years ago

perhaps so fine?

$col["editoptions"] = array("size"=>20, "value"=>'$id_user);

Daniele answered 12 years ago

So ok

$col = array();
$col["title"] = "Id Utente";
$col["name"] = "IDUTENTE";
$col["sortable"] = false; // this column is not sortable
$col["search"] = false; // this column is not searchable
$col["editable"] = true;
$col["editoptions"] = array("value"=>$id_user);
$col["hidden"] = false;
$cols[] = $col;

but there is a problem, when I insert the first record in the IDUTENTE column takes the value of the variable in the correct way, if I insert a new record after, the value is blank.
Use this code to assign the value to the variable

session_start ();
$ id_user = $ _SESSION ['id_user'];

Perhaps the variable is empty after the first insertion, how can I do to preserve the value?

Daniele answered 12 years ago

I have try this but non work

session_start();
$id_user = $_SESSION['id_user'];
session_register($id_user);

Daniele answered 12 years ago

$col["editoptions"] = array("value"=>1);

I did some tests and I noticed that if I put a fixed value (1) and do not use sessions, the problem remains. That is, the first record is inserted correctly with the value 1, the next entries give null value.

Help me please!!!

Abu Ghufran answered 12 years ago

Well, it should work but i will retry it again. Alternate approach is to use on_insert / on_update callback event handlers and set this session value from PHP. For ref, review example file custom-events.php in your paid package.

Regards,

Abu Ghufran answered 12 years ago

Please schedule a remote session at GMT 15 same day.
Meet you on gtalk.

Daniele answered 12 years ago

I'll try the alternative approach to the events, but I'd like to understand what's wrong with what I did, thanks

Daniele answered 12 years ago

Hi, I tried with the example custom-event but I have several problems, I ask you kindly help me on the question that I have made previously, thank you and good day

Daniele answered 12 years ago

can you tell me my local time (in Italy)?

Abu Ghufran answered 12 years ago

Just to help others, i'm logging the solution here.
"recreateForm"=>true was required in add/edit option of form dialog to persist that default value.

Closing this case.

Abdulrahman answered 12 years ago

I am having the same issue and i cannot seem to resolve.

I have added the edit options, but it enters value as 0

what else do i have to do when adding?

$col = array();
$col["title"] = "Users ID";
$col["name"] = "users_id";
$col["sortable"] = false; // this column is not sortable
$col["search"] = false; // this column is not searchable
$col["editable"] = false;
$col["editoptions"] = array("value"=>54);
$col["hidden"] = false;
$cols[] = $col;

Abu Ghufran answered 12 years ago

I've emailed you latest build.
override it, and it should work.

Your Answer

11 + 15 =

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?