Hi,
I have a field in an Add form that do not pass to update query:
$col = array();
$col[“title”] = “Abierto”;
$col[“name”] = “open”;
$col[“fixed”] = true;
$col[“width”] = “60”;
$col[“editable”] = true;
$col[“frozen”] = true;
$col[“formatter”] = “checkbox”;
$col[“edittype”] = “checkbox”;
$col[“editoptions”] = array(“value”=>”Yes:No”, defaultValue=> “Yes”);
$cols[] = $col;
Also I define a field the user cannot modify (called “author”), he can see it on the grid for existing records and I want to set his username called “who” to “author” field when creating a new record. For this I use this, but it doesn’t work either as I see the query doesn’t pass the data (see screenshot).
$col = array();
$col[“title”] = “Autor”;
$col[“name”] = “author”;
$col[“fixed”] = true;
$col[“width”] = “100”;
$col[“editable”] = false;
$col[“viewable”] = true;
$col[“default”] = $_SESSION[‘who’];
$cols[] = $col;
$_SESSION[‘who’] contains the user name and is correctly filled.
Code is here:
https://gist.github.com/ACTIVA-E/edd104a9fd6b40d91b474dbdb5c3d185
Screen shot here : https://imgur.com/a/CiMxjDR
Thank you!
Hello,
Regarding insert error, Can you check ‘evq_todos’ is database view or table? inserts are not allowed in views.
One more point, you need to set need first column of datagrid to be the PK column (unique identifier). It is required for edit, delete operation. It’s usually a autonumber ID of the table. You can set it before your “open” column.
To make field value inserted from session without displaying on add form, you can use on_insert event.
$e[“on_insert”] = array(“add_record”, null, true);
$g->set_events($e);
function add_record($data)
{
$data[“params”][“author”] = $_SESSION[“who”];
}
Ref: Grid Events – Grid 4 PHP Framework Docs (gridphp.com)
To hide column from add dialog, you need to set:
$col[“show”] = array(“list”=>true, “add”=>false, “edit”=>true, “view”=>true, “bulkedit”=>true);
Let me know in case of any ambiguity.
You can also contact back via google hangouts.
id: [email protected]
Thank you Abu,
I still have several problems.
Te reason to use a view is because I want to order the grid on the client’s name (fullname) that is not in the table, as it is codified by an INT in this table. I use a dropdown to show the client’s name on the grid.
Normally a view is “editable” and “appendable” if it affects only one table, meaning if you just enrich data of the main “editable” table. By the way, it works in another grid I have. So, how can I have the grid pre-ordered using $grid[“sortname”] without having the data in the table?
I switched to the table and indead I have no more error message BUT the record still doesn’t register. The message now is “Record added” but it it is NOT recorded in the table. I checked fields names and they are all ok in my PHP coding. Do you have any idea of wath’s happening?
And finally, I don’t understand why adding $_SESSION[‘who’] to the record doesn’t work like this:
$col[“editable”] = false;
$col[“viewable”] = true;
$col[“default”] = $_SESSION[‘who’];
Anyway I will try your solution after solving the record saving issue.
Thank you. Nicolas.
Hi, could you please answer me?
I investigated more on this and changed little things, but Documentation and Demo are not clear and IT STILL DOESN’T WORK.
I use two tables:
“ev_note”, the table of the grid, with “id_address” and “date_add” as primary key. “date_add” is correctly filled with timestamp in the database. “id_address” shoud be filled when adding a new record in the grid throught the dropdown.
I use a view “evq_fullname” with id_address as key and “fullname” field as the customer name for the dropdown
I though it was not creating the record but IT DOES IT BUT WITH “0” AS “id_address”
WHAT’S WRONG? THE “k” VALUE SHOULD CONTAIN THE “id_address” and write it to the database, right?.
Here is the programming of the dropdown:
$col = array();
$col[“title”] = “Cliente”;
$col[“name”] = “id_address”;
$col[“dbname”] = “evq_fullname.id_address”;
$col[“fixed”] = true;
$col[“width”] = “200”;
$col[“frozen”] = true;
$col[“search”] = true;
$col[“editable”] = true;
$col[“edittype”] = “select”; // render as select
# fetch data from database, with alias k for key, v for value
$str = $g->get_dropdown_values(“Select id_address as k, fullname as v From evq_fullname Order By fullname”);
$col[“editoptions”] = array(“value”=>”:Select…;”.$str);
$col[“formatter”] = “select”; // display label, not value
$col[“stype”] = “select”; // enable dropdown search
$col[“searchoptions”] = array(“value” => “:;”.$str);
$col[“editrules”] = array(“required”=>true); // and is required
$cols[] = $col;
Full code here: https://gist.github.com/ACTIVA-E/5fc57be96a31908e4ad9c3a906e6a65b
Pictures here: https://imgur.com/a/F1irzBm
Regards
Hi, I finally changed the structure of the table to have only one primary key adding a unique ID field. I don’t understand why my option was not possible. I bought Grid4Php 2 weeks ago and I was expecting more support.
May I suggest to improve Grid4Php with simple coding. Why do you have to give 10 or 15 parameters for a simple dropdown ? We are loosing a lot of time to set every field of the grid in order and no error messages come.
Hello,
I am so sorry for the delay. Your question is a week old and somehow remain unanswered and closed by mistake on our side. I’m reviewing it now.
With your last message It looks like issue is resolved now.
Please connect with us on google hangouts so we can address the issue via live chat / remote session using
ID: [email protected]