Hide on Add not working?

QuestionsHide on Add not working?
Gary Brett asked 10 years ago

Hi Abu, quick question. I have a column I need to hide on add but display on grid, this also has a default value set which I think is causing an issue?

$col = array();
$col["title"] = "Status"; // caption of column
$col["name"] = "Status"; // grid column name
//$col["editable"] = true;
//$col["hidden"] = false; // hide on grid
//$col["editrules"]["readonly"] = true;
$col["show"] = array("list"=>true, "add"=>false, "edit"=>true, "view"=>true);
$col["width"] = "30";
$col["editoptions"]["defaultValue"] = "Active";
$cols[] = $col;

As it stands the default value of 'Active' doesn't insert to db, if I comment out the col show line and uncomment editable as below it does insert but shows on the add form?

$col = array();
$col["title"] = "Status"; // caption of column
$col["name"] = "Status"; // grid column name
$col["editable"] = true;
$col["width"] = "30";
$col["editoptions"]["defaultValue"] = "Active";
$cols[] = $col;

5 Answers
Abu Ghufran answered 10 years ago

I would recommend to set default value using on_insert event handler.
When you hide, it is removed from add form.

$e["on_insert"] = array("add_client", null, true);
$grid->set_events($e);

function add_client($data)
{
$data["params"]["Status"] = "Active";
}

Gary Brett answered 10 years ago

Thanks Abu, much appreciated.

I already have a function adding/inserting data but the format is slightly different to the solution you posted?

Currently I use;

'{$data[params][Status]}',

Tried adding your $data["params"]["Status"] = "Active"; but it throws errors

Abu Ghufran answered 9 years ago

Screenshot of the error + Code for review would help in checking the issue.

Gary Brett answered 9 years ago

Hi Abu, it doesn't now throw an error but inserts a 0 or a 1 into the db, random?

values ($client_id,
'{$data[params][inputby]}',
'{$data[params][Status]}'='Active',
'{$data[params][CompDate]}',

Changing to

'{$data[params][Status]}Active', works but not sure how!

Thanks anayway

Abu Ghufran answered 9 years ago

Hello,

Please make sure 'Status' field in database table is varchar.
If it is storing 0/1, it looks to be numeric.

Your Answer

8 + 9 =

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?