Demosthenes
asked on
jqGrid passing row number instead of id column
When I inline edit a cell it passes back 1 for id and there is no id of 1. I am assuming it is passing 1 because it is the row number but I really do not know why it is passing 1.
the JSON
Here is what I see in my JSON handler
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQgrid - ASPX</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" ></script>
<!--<script src="http://asp2d:1138/jquery-1.8.3.js"></script>-->
<!--<script src="http://asp2d:1138/jquery-ui-1.9.2.custom.js"></script>-->
<script type="text/javascript" src="http://asp2d:1138/grid.locale-en.js"></script>
<script type="text/javascript" src="http://asp2d:1138/jquery.jqGrid.min.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="http://asp2d:1138/jquery-ui-1.9.2.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="http://asp2d:1138/ui.jqgrid.css" />
<script>
$(function () {
$("#list").jqGrid(
{
url: "/capplanning/SitePages/jsonhandler.aspx?wherefrom=Category One",
datatype: "json",
mtype: "GET",
colNames: ["xyz","category_type","category_value"],
colModel: [{ name: "rr45", sortable: true, key: true, editable:true, hidden: true},
{ name: "category_type", sortable: true, editable:false},
{ name: "category_value", sortable: true, editable:true}],
pager: "#pager",
caption: "Category One",
loadonce: "true",
height: "100%",
cellEdit: true,
cellsubmit: "remote",
cellurl: "/capplanning/SitePages/jsonhandler.aspx?editedgrid=editcategory1",
autowidth: true,
rowNum: 9999,
gridview: true,
multiselect:false
/*rowList:[10,15,20]*/
});
$("#list").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false});
$("#list").jqGrid('navGrid', '#pager', { edit: false, add: true, del: true });
$("#list").jqGrid('navButtonAdd', '#pager',
{
caption: '',
title: 'Show/Hide Filters',
buttonicon: 'ui-icon-arrowthickstop-1-e',
onClickButton: function ()
{
this.toggleToolbar();
if ($.isFunction(this.p._complete))
{
if ($('.ui-search-toolbar', this.grid.hDiv).is(':visible'))
{$('.ui-search-toolbar', this.grid.fhDiv).show();}
else
{$('.ui-search-toolbar', this.grid.fhDiv).hide();}
this.p._complete.call(this);
fixPositionsOfFrozenDivs.call(this);
}
}
});
$("#list")[0].toggleToolbar();
});
</script>
</head>
<body>
<table id="list"><tr><td></td></tr></table>
<div id="pager"></div>
</body>
</html>
the JSON
{"rows":[
{"id":"2","cell":["2","CategoryOne","Maintenancedd"]},
{"id":"3","cell":["3","CategoryOne","Maintenance"]},
{"id":"4","cell":["4","CategoryOne","New Growth"]}
]}
Here is what I see in my JSON handler
Key = category_value Value = Maintenance
Key = id Value = [i][b]1[/b][/i]
Key = oper Value = edit
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Alexandre, I tried this before but whenever I used the jsonReader any row that is clicked on becomes highlighted, and stays highlighted. I even have multiselect:false and it still high lights any and all rows that are clicked on.
<script>
/* setup the grid */
$(function () {
$('#list').jqGrid(
{
url: '/capplanning/SitePages/jsonhandler.aspx?wherefrom=Category One',
datatype: 'json',
mtype: 'GET',
colNames: ['category_id','category_type','category_value'],
colModel: [{ name:'category_id'},
{ name: 'category_type', sortable: true, editable:false},
{ name: 'category_value', sortable: true, editable:true}],
pager: '#pager',
caption: 'Category One',
loadonce: 'true',
height: '100%',
cellEdit: true,
cellsubmit: 'remote',
cellurl: '/capplanning/SitePages/jsonhandler.aspx?editedgrid=editcategory1',
autowidth: true,
rowNum: 9999,
jsonReader : {
root:"rows",
cell: "cell",
id: "id"
}
/*rowList:[10,15,20]*/
});
/*End grid setup*/
$('#list').jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false}); /* set up Filter toolbar */
$('#list').jqGrid('navGrid', '#pager', { edit: false, add: true, del: true }); /* Show the bottom bar "Pager"*/
$('#list').jqGrid('navButtonAdd', '#pager', /* Set up Filter toggle button*/
{
caption: '',
title: 'Show/Hide Filters',
buttonicon: 'ui-icon-arrowthickstop-1-e',
onClickButton: function ()
{
this.toggleToolbar();
if ($.isFunction(this.p._complete))
{
if ($('.ui-search-toolbar', this.grid.hDiv).is(':visible'))
{$('.ui-search-toolbar', this.grid.fhDiv).show();}
else
{$('.ui-search-toolbar', this.grid.fhDiv).hide();}
this.p._complete.call(this);
fixPositionsOfFrozenDivs.call(this);
}
}
});
$('#list')[0].toggleToolbar(); /* call the function so the Filters are hidden on startup*/
});
</script>
{"rows":[
{"id":"2","cell":["2","CategoryOne","Cost Reduction"]},
{"id":"3","cell":["3","CategoryOne","Maintenance"]},
{"id":"4","cell":["4","CategoryOne","New Growth"]}
]}
ASKER
I don't know how to delete a comment so I will just post that I had changed the id column name and forgot to change it in the new jsonReader section. I changed
to
So it matches the column in the colModel.
jsonReader : {
root:"rows",
cell: "cell",
id: "id"
}
to
jsonReader : {
root:"rows",
cell: "cell",
id: "category_id"
}
So it matches the column in the colModel.
ASKER
I just threw in some code I found on the internet to deal with the rows highlighting, it seems to work so I will post it.
$('#list').jqGrid().focusout(function () /* unselect row after lose focus::fix for row sel issue */
{
$('#list').jqGrid("resetSelection");
});
I don't see how that behavior can be related to the jsonReader config itself.
It might indeed be a side effect for the fact that with it you are reading the data correctly.
Do you use any custom CSS?
It might indeed be a side effect for the fact that with it you are reading the data correctly.
Do you use any custom CSS?
I remembered that resetSelection option, but I'm not sure how it behaves with the celledit.
Works well?
Works well?
ASKER
No, I am grasping at straws now. Here seems to be the issue.
json returns this
My colum model looks like this.
When my reader code looks like this: the row number is only passed
jsonReader : {
root:"rows",
cell: "cell",
id: "category_id"
}
When my reader code looks like this: the id is passed correctly BUT, all my rows start highlighting, the type of behavior you would expect if the grid had no id or key set.
jsonReader : {
root:"rows",
cell: "cell",
id: "category_id"
}
json returns this
{"rows":[
{"id":"2","cell":["2","CategoryOne","Cost Reduction"]},
{"id":"3","cell":["3","CategoryOne","Maintenance"]},
{"id":"4","cell":["4","CategoryOne","New Growth"]}
]}
My colum model looks like this.
colNames: ['category_id','category_type','category_value'],
colModel: [{ name:'category_id'},
When my reader code looks like this: the row number is only passed
jsonReader : {
root:"rows",
cell: "cell",
id: "category_id"
}
When my reader code looks like this: the id is passed correctly BUT, all my rows start highlighting, the type of behavior you would expect if the grid had no id or key set.
jsonReader : {
root:"rows",
cell: "cell",
id: "category_id"
}
ASKER
should have been
jsonReader : {
root:"rows",
cell: "cell",
}
jsonReader : {
root:"rows",
cell: "cell",
id: "id"}
ASKER
What I am thinking is as a workaround maybe I can just deselect the last selected row if that is possible but so far I havent found good code for that. I could keep
jsonReader : {
root:"rows",
cell: "cell",
id: "id"
}
And just unselect the last selected row. Or unselect every row except the one being clicked on or selected.
jsonReader : {
root:"rows",
cell: "cell",
id: "id"
}
And just unselect the last selected row. Or unselect every row except the one being clicked on or selected.
Open in new window
shouldn't that be a reference also, but if you have a "1" there, it would always show one, no matter the id ?Or maybe I don't see your intent?