Adding record leaves one blank field

QuestionsAdding record leaves one blank field
Rudy asked 11 years ago

I have a table where the primary index is a VARCHAR column called 'id'.

I have it loaded in PHPGrid using this code:

$col["title"]="ID";
$col["name"]="id";
$col["editable"]=true;
$col["viewable"]=false;
$col["hidden"]=false;
$col["resizable"]=true;

The table is rendered using:

$gA->set_actions(array("add"=>true,"edit"=>true,"delete"=>false,"view"=>true,"rowactions"=>false,"export"=>true,"autofilter"=>true,"search"=>"simple","inlineadd"=>false,"showhidecolumns"=>false));

When adding a new row to the table using PHP Grid, I fill in all the details in all the fields as necessary and the row is added, but 'id' is always blank in the table. All other fields are filled in fine.

Why does this happen?

6 Answers
Abu Ghufran answered 11 years ago

You have set ID as hidden, so you will not be entering it from form.
Unless it is auto_increment or have some default value, it will always update as blank.
Either make it non-hidden and enter its data, or set some default value.

Rudy answered 11 years ago

Thanks.

Note that with the settings I have pasted above, the "ID" field shows up as text box on the Add Row dialog box (clicking the '+' icon). But no matter what I type inside, it always saves as blank.

I have tried setting '$col["viewable"]=true' and removing the line '$col["hidden"]=false', but the problem is still there.

It doesn't matter what I type in the "ID" field when adding new row, the row is always blank. Note that this cannot be auto increment – the table is designed to have ID as VARCHAR type.

Please help!

Rudi

Abu Ghufran answered 11 years ago

This is very unusual, hidden option does not show field in dialog, unless you set edithidden: true which is not set in your case.
Can you email me your grid code. I'll recheck and reply back.

You can email me at [email protected]

Rudy answered 11 years ago

Full code as below:

————————————————————–

// Invoke phpGrid
require_once("phpgrid/inc/jqgrid_dist.php");
$gA=new jqgrid();

// Variables
$grid["caption"]="Edit Products";

// Define Columns
unset($cols);
########################
$col["title"]="ID";
$col["name"]="id";
$col["editable"]=true;
$col["viewable"]=true;
$col["resizable"]=true;
$col["align"]="center";
$col["width"]="30";
$cols[]=$col;unset($col);
########################
$col["title"]="Category";
$col["name"]="maincat";
$col["hidden"]=true;
$col["editable"]=true;
$col["viewable"]=true;
$col["resizable"]=true;
$col["align"]="center";
$col["width"]="30";
$col["editrules"] = array("edithidden"=>true);
$col["edittype"]="select";
$strMaincat=$gA->get_dropdown_values("SELECT DISTINCT id AS k, name AS v FROM maincats");
$col["editoptions"]=array("value"=>$strMaincat);
$cols[]=$col;unset($col);
########################
$col["title"]="Brand";
$col["name"]="brand";
$col["hidden"]=true;
$col["editable"]=true;
$col["viewable"]=true;
$col["resizable"]=true;
$col["align"]="center";
$col["width"]="30";
$col["editrules"] = array("edithidden"=>true);
$col["edittype"]="select";
$strBrands=$gA->get_dropdown_values("SELECT DISTINCT id AS k, name AS v FROM brands");
$col["editoptions"]=array("value"=>$strBrands);
$cols[]=$col;unset($col);
########################
$col["title"]="Name";
$col["name"]="name";
$col["editable"]=true;
$col["viewable"]=true;
$col["resizable"]=true;
$cols[]=$col;unset($col);
########################
$col["title"]="Price";
$col["name"]="price";
$col["editable"]=true;
$col["viewable"]=true;
$col["resizable"]=true;
$col["align"]="center";
$col["width"]="20";
$cols[]=$col;unset($col);
########################
$col["title"]="Active";
$col["name"]="active";
$col["editable"]=true;
$col["viewable"]=true;
$col["resizable"]=true;
$col["align"]="center";
$col["width"]="20";
$cols[]=$col;unset($col);
########################
$col["title"]="Keywords";
$col["name"]="keywords";
$col["editable"]=true;
$col["viewable"]=false;
$col["resizable"]=false;
$col["align"]="center";
$col["hidden"] = true;
$col["editrules"]=array("edithidden"=>true);
$cols[]=$col;unset($col);
########################
$col["title"]="Sale Price";
$col["name"]="sale";
$col["editable"]=true;
$col["viewable"]=true;
$col["resizable"]=true;
$col["align"]="center";
$col["hidden"] = true;
$col["editrules"]=array("edithidden"=>true);
$cols[]=$col;unset($col);
########################
$col["title"]="Description";
$col["name"]="description";
$col["editable"]=true;
$col["viewable"]=true;
$col["resizable"]=true;
$col["hidden"] = true;
$col["align"]="center";
$col["edittype"] = "textarea";
$col["editoptions"] = array("rows"=>8,"cols"=>70);
$col["editrules"]=array("edithidden"=>true);
$cols[]=$col;unset($col);

// Render Table
$gA->set_actions(array("add"=>true,"edit"=>true,"delete"=>false,"view"=>true,"rowactions"=>false,"export"=>true,"autofilter"=>true,"search"=>"simple","inlineadd"=>false,"showhidecolumns"=>false));
$gA->table = "products";
$grid["autofilter"]=false;
$grid["width"]="960";
$grid["resizable"] = false;
$grid["rowNum"] = 1000;
$grid["pgbuttons"] = false;
$grid["viewrecords"] = false;
$grid["pgtext"] = null;
$grid["rowList"] = array();
$gA->set_options($grid);
$gA->set_columns($cols);
$gA_out=$gA->render("list1");

————————————————————–

SQL table construction:

CREATE TABLE IF NOT EXISTS `products` (
`id` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
`maincat` int(10) NOT NULL,
`brand` int(10) NOT NULL,
`name` varchar(500) COLLATE utf8_unicode_ci NOT NULL,
`keywords` varchar(500) COLLATE utf8_unicode_ci NOT NULL,
`price` decimal(10,2) NOT NULL,
`sale` decimal(10,2) NOT NULL,
`description` text COLLATE utf8_unicode_ci NOT NULL,
`active` int(1) unsigned NOT NULL DEFAULT '1',
PRIMARY KEY (`id`),
FULLTEXT KEY `mainsearch` (`name`,`keywords`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

————————————————————-

Hope you can help!

Abu Ghufran answered 11 years ago

Hello,

I regenerated this issue.

You need to replace 2 lines in jqgrid_dist.php (2 places)

Replace
unset($data['id']);

with

if ($pk_field != "id")
unset($data['id']);

Also email me your ordernumber to get latest build

Rudy answered 11 years ago

Thanks! It works fine now.

Your Answer

1 + 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?