No Editable but Viewable on Add

QuestionsNo Editable but Viewable on Add
S19K15 asked 6 years ago

Hi, is there any way to have a field that is not editable but still viewable when add dialog box is displayed? I tried something without success.

For example:
$col_detail_prac = array();
$col_detail_prac["title"] = $WORDING_STUDENT;
$col_detail_prac["name"] = "IDStud";
$col_detail_prac["search"] = true;
$col_detail_prac["editable"] = false;
$col_detail_prac["editrules"] = array("required"=>true);
$col_detail_prac["show"] = array("list"=>true,"view"=>true,"edit"=>true,"add"=>true);
$cols_detail_prac[] = $col_detail_prac;

Also can this field have a value behind and a different string in front view like the select type of field but without being select?

For example:
$str_stud = $jqgrid->get_dropdown_values("SELECT DISTINCT IDNumb as k, Plat as v FROM student");
$col_detail_prac["editoptions"] = array("value" => $str_stud, "separator" => ":", "delimiter" => ";");

17 Answers
Abu Ghufran answered 6 years ago

Little clarification required.
Add dialog does have any data. It's usually a blank form to input data. How you want a view-only field there and what should be there to be viewed in add form.

If you can tell exact business case, i can suggest better.

S19K15 answered 6 years ago

Correct, i missed to clarify that i am reffering to a master-detail-tab-grid and i have selected a record on the master and the requirement is to display the refering record on the add dialog without being able to change it!

Abu Ghufran answered 6 years ago

Screenshot: http://prntscr.com/idrzjy
Code: https://gist.github.com/gridphp/05bd222c0c262081640611b3594c26bd

Step1: In list1
$opt["add_options"]["afterShowForm"] = 'function() { var selr = jQuery("#list1").jqGrid("getGridParam","selrow"); jQuery("#client_id").val( selr ) }';
$grid->set_options($opt);

Step2: In list2
$col["editable"] = true;
$col["editoptions"] = array("readonly"=>"readonly", "style"=>"border:0");

Step3: In list2, to save on post back
$e["on_insert"] = array("add_client", null, true);
$grid->set_events($e);

function add_client(&$data)
{
$id = intval($_GET["rowid"]);
$data["params"]["client_id"] = $id;
}

S19K15 answered 6 years ago

Thanks, is there any way to change the display value of id to First and Last Name using sql query in this field without beeing select type?

Abu Ghufran answered 6 years ago

If your master grid has firstname column, then you can use

$opt["add_options"]["afterShowForm"] = 'function() {
var selr = jQuery("#list1").jqGrid("getGridParam","selrow");
var val = jQuery('#list1').jqGrid('getCell', selr, 'firstname');
jQuery("#client_id").val( val )
}';

Abu Ghufran answered 6 years ago

I am sending you working demo of master detail with clients->invoices scenario.
https://gist.github.com/gridphp/05bd222c0c262081640611b3594c26bd

S19K15 answered 6 years ago

Hi Abu, all of your answers are correct but i am trying to do a mixed of all these, so i will clarify it a little more.

I have a master-detail-tab-grids and the master contains the students, the detail contains the lessons which each student has taken.

When master is focused on a record the detail lesson grid is refreshing.
Done, with code:
$grid["detail_grid_id"] = "lessons";
$grid["subgridparams"] = "idnumb";

When detail is adding a record it gets the student id on a record the detail lesson grid is refreshing.
Done, with code:
$col_detail_prac = array();
$col_detail_prac["title"] = $WORDING_STUDENT;
$col_detail_prac["name"] = "IDStud";
$col_detail_prac["search"] = true;
$col_detail_prac["editable"] = false;
$col_detail_prac["editrules"] = array("required"=>true);
$cols_detail_prac[] = $col_detail_prac;

function lesson(&$data)
{
$id = intval($_GET["idnumb"]);
$data["params"]["IDStud"] = $id;
}

Regarding the detail grid, the ID of student on lesson table is the idnumb of student in student table and the column i use in order to store the IDStud in lesson table is displaying the id of student, so is possible to display the fisrt and last name of the student with sql in this column and behind the scenes the idnumb is stored in the database?

Then i want to display this first and last name predifined when add dialog box is open but with sql and not javascript using the $_GET["idnumb"] in order just to be sure the the record is going to be added belongs to the specified student.

S19K15 answered 6 years ago

In you example, in the Detail-Grid, the [client_id] column is showing the id of client which is inherited from Master-Grid when added, it is not showing the First and Last Name of this client_id…

Abu Ghufran answered 6 years ago

Referring above demo, here is the screenshot: http://prntscr.com/ieng1m
line 68

S19K15 answered 6 years ago

Yes Abu, i saw it, i mean on the Detail-Grid-Rows, there you display the ID as a number, i am asking if there is a way to change also this behavior also in the rows.

Abu Ghufran answered 6 years ago

You can make inner join in detail grid sql_command to select full name and display on grid as column with editable:false.
You can make id column hidden on list and display rest.
$col["show"] = array("list"=>false,"edit"=>true,"add"=>true,"view"=>false);

S19K15 answered 6 years ago

Perfect Abu,
This solves one part of the requirement, the second one, with the first and last name on add dialog box can be done with javascript…

$opt["add_options"]["afterShowForm"] = 'function() {
var selr = jQuery("#list1").jqGrid("getGridParam","selrow");
var val = jQuery('#list1').jqGrid('getCell', selr, 'firstname');
jQuery("#client_id").val( val )
}';

but can i do it with php something like…

$first = intval($_GET["first"]);
$last = intval($_GET["last"]);

Abu Ghufran answered 6 years ago

It will be in $_GET If you set:

$grid["subgridparams"] = "idnumb,first,last";
given that first,last are column names of parent grid.

As they are strings, intval is not required.

$first = ($_GET["first"]);
$last = ($_GET["last"]);

S19K15 answered 6 years ago

Correct, sorry about that, and how can i set them on the add dialog box of the Detail-Grid?

Abu Ghufran answered 6 years ago

perhaps I don't understand. i mean this was already told in previous reply http://prntscr.com/ieng1m

S19K15 answered 6 years ago

Yes but the value of First Name and Last Name for Add dialog box on Detail-Grid you got it with JavaScript! I need to get it with php!

Abu Ghufran answered 6 years ago

Currently It's not doable with PHP code. There is some code limitation in our lib.

Your Answer

1 + 5 =

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?