Forum
11:14
25/01/2011
Hi
I have a problem of Adding a New Record in the Subgrid of Treegrid. [In the 2 - nested level and 3 - nested level ].
I have referred the Treegrid (3-nested levels).
The Url link is : /phpjqgrid/examples/hierarchy/subgrid_3_levels/default.php
I am currently customizing the Treegrid which is given in the above url.
I have a main grid, named "Scheduling : Milestone", Here i am able to add a new record. In the next level(2-nested level) of this Treegrid, named as "Scheduling : Activity", I am unable to add a new Record. Also in the (3 – nested level of this grid) named as "Scheduling : Task", Here too i am unable to add new Record.
I list the code of this subgrid (2-nested level) and subsubgrid (3-nested level).
Please tell me what is the wrong in my code. And help me to solve the problem of Adding a New Record in the subgrid and subsubgrid.
This is my customized Treegrid structure.
+ Scheduling : Milestone [1 - nested level]
+Scheduling : Activity [2 - nested level]
+Scheduling : Task [3 - nested level]
DB Structure:
I am using two db tables.
For 2- nested level, I am using a db table called "tbl_activity". This contains 3 db fields (ActivityId BIGINT Primary Key AUTO INCREMENT, ActivityName Text, MilestoneId BIGINT FOREIGN KEY REFERENCES tbl_milestone)
For 3- nested level, I am using a db table called "tbl_scheduling". This contains 14 db fields (TaskId BIGINT Primary Key AUTO INCREMENT, TaskName Text, Size Int, Complexity VARCHAR(20), Variance Int, StartDate DATETIME, TargetDate DATETIME, Days Int, EffortHours Int, ActualHours Int, Priority Int, Resources VARCHAR(40), Status VARCHAR(20), ActivityId BIGINT FOREIGN KEY REFERENCES tbl_activity)
I am unable to add a new record in both the 2nd nested and 3rd nested levels.
1. subgrid.php:
<?php
require_once 'jq-config.php';
// include the jqGrid Class
require_once ABSPATH."php/jqGrid.php";
// include the driver class
require_once ABSPATH."php/jqGridPdo.php";
// include the datepicker class
require_once ABSPATH."php/jqCalendar.php";
// Connection to the server
$conn = new PDO(DB_DSN,DB_USER,DB_
// Tell the db that we use utf-8
$conn->query("SET NAMES utf8″);
// Get the needed parameters passed from the main grid
$subtable = jqGridUtils::Strip($_REQUEST["subgrid"]);
$rowid = jqGridUtils::Strip($_REQUEST["rowid"]);
if(!$subtable && !$rowid) die("Missed parameters");
// Create the jqGrid instance
$grid = new jqGridRender($conn);
// Write the SQL Query
$grid->SelectCommand = 'SELECT ActivityId, ActivityName FROM tbl_activity WHERE MilestoneId= ?';
//, tbl_milestone tm tm.MilestoneId = ta.MilestoneId'
// set the ouput format to json
$grid->dataType = 'json';
$grid->table = 'tbl_activity';
$grid->setPrimaryKeyId("ActivityId");
//$grid->serialKey = false;
// Let the grid create the model
$grid->setColModel(null, array(&$rowid));
// Set the url from where we obtain the data
$grid->setUrl('subgrid.php');
// add a action column and instruct the formatter to create the needed butons
// for inline editing
$grid->addCol(array(
"name"=>"Actions",
"formatter"=>"actions",
"editable"=>false,
"sortable"=>false,
"resizable"=>false,
"fixed"=>true,
"width"=>50,
// use keys to save or cancel a row.
"formatoptions"=>array("keys"=>true)
), "first");
// Set some grid options
$grid->setGridOptions(array(
"rownumbers"=>true,
"rownumWidth"=>30,
"width"=>540,
"rowNum"=>10,
"sortname"=>"ActivityId",
"caption"=>"Scheduling : Activity",
"width"=>950,
"height"=>'auto',
"postData"=>array("subgrid"=>$subtable,"rowid"=>$rowid)));
$grid->setColProperty("ActivityId", array("label"=>"Activity ID", "editable"=>false, "sortable"=>false));
$grid->setSubGridGrid("subsubgrid.php");
$grid->navigator = true;
$grid->setNavOptions('navigator', array("excel"=>false,"add"=>true,"edit"=>true,"del"=>true,"view"=>true));
// Enjoy
$subtable = $subtable."_t";
$pager = $subtable."_p";
$grid->renderGrid($subtable,$pager, true, null, array(&$rowid), true,true);
$conn = null;
?>
require_once 'jq-config.php';
// include the jqGrid Class
require_once ABSPATH."php/jqGrid.php";
// include the driver class
require_once ABSPATH."php/jqGridPdo.php";
// include the datepicker class
require_once ABSPATH."php/jqCalendar.php";
// Connection to the server
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
// Tell the db that we use utf-8
$conn->query("SET NAMES utf8″);
// Get the needed parameters passed from the main grid
$subtable = jqGridUtils::Strip($_REQUEST["subgrid"]);
$rowid = jqGridUtils::Strip($_REQUEST["rowid"]);
if(!$subtable && !$rowid) die("Missed parameters");
// Create the jqGrid instance
$grid = new jqGridRender($conn);
// Write the SQL Query
$grid->SelectCommand = 'SELECT s.TaskId, s.TaskName, s.Size, s.Complexity, s.Variance, s.StartDate, s.TargetDate, s.Days, s.EffortHours, s.ActualHours, s.Priority, s.Resources, s.Status FROM scheduling s WHERE s.ActivityId=?';
//, tbl_activity ta ta.ActivityId = s.ActivityId
// set the ouput format to json
$grid->dataType = 'json';
// Set the table to where you update the data
$grid->table = 'scheduling';
// We tell that the primary key is not serial, which should be inserted by the user
$grid->serialKey = false;
$grid->setPrimaryKeyId("TaskId");
// Let the grid create the model
$grid->setColModel(null, array(&$rowid));
// Set the url from where we obtain the data
$grid->setUrl('subsubgrid.php');
// add a action column and instruct the formatter to create the needed butons
// for inline editing
$grid->addCol(array(
"name"=>"Actions",
"formatter"=>"actions",
"editable"=>false,
"sortable"=>false,
"resizable"=>false,
"fixed"=>true,
"width"=>50,
// use keys to save or cancel a row.
"formatoptions"=>array("keys"=>true)
), "first");
// Set some grid options
$grid->setGridOptions(array(
"rownumbers"=>true,
"rownumWidth"=>30,
"width"=>480,
"rowNum"=>10,
"sortname"=>"TaskId",
"caption"=>"Scheduling : Task",
"width"=>950,
"height"=>'auto',
"postData"=>array("subgrid"=>$subtable,"rowid"=>$rowid)));
// Change some property of the field(s)
$grid->setColProperty("TaskId", array("label"=>"ID", "editable"=>false, "hidden"=>true,"sortable"=>false, "width"=>0));
$grid->setColProperty("TaskName", array("label"=>"Task", "width"=>580));
$grid->setColProperty("Size", array("label"=>"Size","align"=>"right", "width"=>65));
$grid->setColProperty("Complexity", array("label"=>"Complexity","align"=>"left", "width"=>185));
$grid->setColProperty("Variance", array("label"=>"VR(%)","align"=>"right", "editable"=>false, "width"=>85));
$grid->setColProperty("StartDate", array("label"=>"Start", "align"=>"left","width"=>180,
"formatter"=>"date",
"formatoptions"=>array("srcformat"=>"Y-m-d H:i:s","newformat"=>"m/d/Y")
)
);
$grid->setColProperty("TargetDate", array("label"=>"Target", "align"=>"left","width"=>180,
"formatter"=>"date",
"formatoptions"=>array("srcformat"=>"Y-m-d H:i:s","newformat"=>"m/d/Y")
)
);
$grid->setColProperty("Days", array("label"=>"Day(s)","align"=>"right", "width"=>100));
$grid->setColProperty("EffortHours", array("label"=>"EH","align"=>"right", "width"=>75));
$grid->setColProperty("ActualHours", array("label"=>"AH","align"=>"right", "editable"=>false, "width"=>95));
$grid->setColProperty("Priority", array("label"=>"Priority","align"=>"right", "width"=>115));
$grid->setColProperty("Resources", array("label"=>"Resources","align"=>"left", "width"=>300));
$grid->setColProperty("Status", array("label"=>"Status","align"=>"left", "width"=>165));
//$grid->setSelect("ScheduleStatus","SELECT DISTINCT StatusId, ScheduleStatus FROM schedule_status ORDER BY StatusId",false, true, true, array(""=>"All"));
//Status-Hardcoded
$mystatus = array("Open"=>"Open", "Inprogress"=>"Inprogress", "Close"=>"Close", "Suspended"=>"Suspended");
$grid->setSelect("Status", $mystatus); //, false, false, true, array(""=>"All")
//Resources-Hardcoded
$myresources = array("Arul"=>"Arul","Beschi"=>"Beschi", "Gopal"=>"Gopal", "James"=>"James", "Jenifer Nishanth"=>"Jenifer Nishanth", "Nobel"=>"Nobel");
$grid->setSelect("Resources", $myresources);
//Complexity-Hardcoded
$mycomplexity = array("Simple"=>"Simple","Normal"=>"Normal", "Medium"=>"Medium", "Complex"=>"Complex");
$grid->setSelect("Complexity", $mycomplexity);
// Set the datepicker on OrderDate field. Note that the script automatically
// converts the user date set in the jqGrid
$grid->setDatepicker('StartDate', array("buttonIcon"=>true), true, false);
$grid->datearray = array('StartDate');
$grid->setDatepicker('TargetDate', array("buttonIcon"=>true), true, false);
$grid->datearray = array('TargetDate');
$grid->navigator = true;
$grid->setNavOptions('navigator', array("excel"=>false,"add"=>true,"edit"=>true,"del"=>true,"view"=>true));
// Enjoy
$subtable = $subtable."_t";
$pager = $subtable."_p";
$grid->renderGrid($subtable,$pager, true, null, array(&$rowid), true,true);
$conn = null;
?>
Thanks in advance.
Most Users Ever Online: 715
Currently Online:
21 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66