Master-detail receive id form parent grid where value is alphanumeric

QuestionsMaster-detail receive id form parent grid where value is alphanumeric
John asked 10 years ago

Hi,

I would like to receive id from the parent grid which value contain number and character.

All the master detail sample that I have seen only receive id for either only contain character or integer.
$id = intval($_GET["rowid"]);
$gender = $_GET["gender"];
$company = $_GET["company"];
$cid = intval($_GET["client_id"]);

If i have client_id as "cl123", what would be the code to receive the id from the parent grid?
I have tried "$cid = $_GET["client_id"];" which doesnt work.

Thanks,
John

3 Answers
Abu Ghufran answered 10 years ago

The charaters also incorporate the numeric values, so 'company' or 'gender' code example applies for your case.
There could be some other issue in code.

Check there should be no spaces b/w comma sep values.
$opt["subgridparams"] = "client_id,gender,company";

John answered 10 years ago

Hi Abu,

I tried to run it but it doesnt work.

Below is the code that I am using to create the master detail fancy grid.

When I run this code, it shows
~~
Couldn't execute query. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 1 OFFSET 0' at line 1 – SELECT id,TOW_ID,timestamp,Additional_Information,'' as 'Address' FROM data_submit WHERE TOW_ID = LIMIT 1 OFFSET 0
~~

Ticket_Of_Work and Address both contain character and numeric value.

// master grid
$grid = new jqgrid();
$opt["caption"] = "Clients Data";
// following params will enable subgrid — by default first column (PK) of parent is passed as param 'id'
$opt["detail_grid_id"] = "list2";

// extra params passed to detail grid, column name comma separated
$opt["subgridparams"] = "Ticket_Of_Work,Address";
$opt["export"] = array("filename"=>"my-file", "sheetname"=>"test", "format"=>"pdf");
$opt["export"]["range"] = "filtered";
$grid->set_options($opt);
$grid->table = "sod_sa";

$col = array();
$col["title"] = "TOW";
$col["name"] = "Ticket_Of_Work";
$col["width"] = "20";
$col["editable"] = true;
$cols[] = $col;

$col = array();
$col["title"] = "Address";
$col["name"] = "Address";
$col["editable"] = true;
$col["width"] = "80";
$cols[] = $col;

$col = array();
$col["title"] = "Detail Info";
$col["name"] = "detail";
$col["default"] = "<a class='fancybox' onclick='jQuery("#list1").setSelection({Ticket_Of_Work});' href='#box_detail_grid'>View Details</a>";
$col["width"] = "40";
$col["editable"] = true;
$col["search"] = false;
$col["export"] = false;
$cols[] = $col;

$grid->set_columns($cols);

$grid->set_actions(array(
"add"=>true, // allow/disallow add
"edit"=>true, // allow/disallow edit
"delete"=>true, // allow/disallow delete
"rowactions"=>false, // show/hide row wise edit/del/save option
"export"=>true, // show/hide export to excel option
"autofilter" => true, // show/hide autofilter for search
"search" => "advance" // show single/multi field search condition (e.g. simple or advance)
)
);

$out_master = $grid->render("list1");

// detail grid
$grid = new jqgrid();

$opt = array();
$opt["sortname"] = 'TOW_ID'; // by default sort grid by this field
$opt["sortorder"] = "desc"; // ASC or DESC
$opt["height"] = ""; // autofit height of subgrid
$opt["caption"] = "Invoice Data"; // caption of grid
$opt["multiselect"] = true; // allow you to multi-select through checkboxes
$opt["export"] = array("filename"=>"my-file", "sheetname"=>"test", "format"=>"pdf"); // export to excel parameters
$opt["export"]["range"] = "filtered";
// Check if master record is selected before detail addition
$opt["add_options"]["beforeInitData"] = "function(formid){ var selr = jQuery('#list1').jqGrid('getGridParam','selrow'); if (!selr) { alert('Please select master record first'); return false; } }";
$grid->set_options($opt);

$grid->set_actions(array(
"add"=>true, // allow/disallow add
"edit"=>true, // allow/disallow edit
"delete"=>true, // allow/disallow delete
"rowactions"=>true, // show/hide row wise edit/del/save option
"autofilter" => true, // show/hide autofilter for search
"search" => false // show single/multi field search condition (e.g. simple or advance)
)
);

// receive id, selected row of parent grid
$id = intval($_GET["rowid"]);
$Address = $_GET["Address"];
$TOW = $_GET["Ticket_Of_Work"];

// for non-int fields as PK
// $id = (empty($_GET["rowid"])?0:$_GET["rowid"]);

// and use in sql for filteration
$grid->select_command = "SELECT id,TOW_ID,timestamp,Additional_Information,'$Address' as 'Address' FROM data_submit WHERE TOW_ID = $TOW";
// this db table will be used for add,edit,delete
$grid->table = "data_submit";

$cols = array();

(REMOVED DUE TO LENGTH 5KB)

$cols[] = $col;

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

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

// generate grid output, with unique grid name as 'list1'
$out_detail = $grid->render("list2");

Abu Ghufran answered 10 years ago

The $TOW cannot be accessed inside function as both have different scope.

// receive id, selected row of parent grid
$id = intval($_GET["rowid"]);
$Address = $_GET["Address"];
$TOW = $_GET["Ticket_Of_Work"];

function add_client(&$data)
{
$id = intval($_GET["rowid"]);
$TOW = $_GET["Ticket_Of_Work"]; // <———————- Need to defined inside function
$data["params"]["TOW_ID"] = $TOW;
}

Your Answer

15 + 4 =

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?