Forum


02:12

09/03/2010

How can I retrive just a column ID from column A when inside event of column B. Type of column A is select and editing is inline. I know that similar question was asked a couple of times but I can't find a solution nomather what I try I always get html construct.
This returns html construct: <select class= …
var rowid = $("#link_categories").jqGrid('getGridParam','selrow');
var row_values = jQuery("#link_categories").jqGrid('getRowData',rowid);
This returns undefined error
jQuery("#" + (rowId-1) + "_supplier_short_name")[0].value
// ————————- grid definition ——————————-
jQuery(document).ready(function(){
jQuery("#link_categories").jqGrid({
colModel:[
{name:'supplier_short_name', index:'supplier_short_name', editable: true,
edittype:"select", editrules:{required:true}, formatter:'select',
editoptions:{ value:"1:A;2:B;3:C;4:D"}},
{name:'category_entity_id',editable: true, formatter:'select', search: true, edittype:"select",
editoptions:{
dataUrl:'link_categories.php?oper=grid_lookup_category_entity_id',
value:{0:'A',1:'B'},
dataEvents :[{
type: 'click',
fn: function(e){
var rowid = $("#link_categories").jqGrid('getGridParam','selrow');
var row_values = jQuery("#link_categories").jqGrid('getRowData',rowid);
// var supplier_short_name = $('#' + rowid + '_supplier_short_name').val();
// alert(supplier_short_name)
$.get('link_categories.php?oper=grid_lookup_category_entity_id&value='+row_values['supplier_short_name']
,function(data){
var res = $(data).html();
$("#category_entity_id").html(res);
], }, } }] } ); }
onSelectRow: function(id){
if(id && id!==lastsel){
jQuery('#link_categories').jqGrid('saveRow',lastsel);
jQuery('#link_categories').jqGrid('editRow',id,true);
lastsel=id;
}); }, }
19:07

09/03/2010

The problem why I can't get value using jquery is because the definition of id of the column:
var rowid = $("#link_categories").jqGrid('getGridParam','selrow');
jQuery("#" + (rowId-1) + "_supplier_short_name")[0].value
RowId is not just a simple number, but string combined from 3 columns which can contain non standard characters.
ie: '#Field_1_Field_2_Field_3_Column_name' where Field_1 is "stra#+ n – ge Äar"
The definition from php file:
$responce->rows[$i]['id'] = array($row[supplier_short_name],$row[supplier_category],$row[category_entity_id]);
My question is how to escape these strange characters that will mathc jqgrid definition ( ie: that I will get the same string for column id as jqgrid ). I tryed javascript encodeURIComponent(rowid) function but it is not working (my knowledge of javascript is very limited:(
22:17

10/08/2009

Sorry but I not really understand your question. You posted code without enough description what you want achieve with the code.
The names on jqGrid columns you define yourself to use it in the JavaScript only. If you have some problems with long names included special characters why you not just choose more simple names for the columns?
If you want to build ids used by jqGrid you should use $.jgrid.jqID function.
Best regards
Oleg
01:49

09/03/2010

First of, thank you for replying to my post, I am bashing my head against the wall for two days with this problem.
I will try to explane better.
When grid is in edit mode I would like to select value of column A ( edittype : select ) when inside dataEvent 'click' in column B ( column goes into inline edit mode on row select)
ColModel definition of column A (supplier_short_name) and column B (category_entity_id).
{name:'supplier_short_name',index:'supplier_short_name',editable: true, edittype:"select",formatter:'select'},
{name:'category_entity_id',editable: true, formatter:'select', search: true, edittype:"select",
editoptions:{ dataEvents :[{type: 'click'...
If I try to get the value the jqgrid way
var row_values = jQuery("#link_categories").jqGrid('getRowData',rowid);
I get html string despite the fact that formatter of column A is set to select ( formatter:'select'). So instead the value of the column I get html construct of the column ( <select class= .... </select>)
So the only solution is to get the value with direct jquery request which is
jQuery("#" + (rowId) + "_supplier_short_name")[0].value
The rowid in my case is defined by values in 3 different columns. Values are not just numbers but can be anything. That is defined in php script:
$responce->rows[$i]['id'] = array($row[supplier_short_name],$row[supplier_category],$row[category_entity_id]);
$responce->rows[$i]['cell'] = array($row[supplier_short_name],$row[supplier_category],$row[category_entity_id],$row[attribute_set_id],$row[adTimeIns],$row[adTimeChg]);
$i++;
}
echo json_encode($responce);
When jqgid is constructed the id of a column is #RowId_ColumnName where RowId is not just a number but combined value of 3 columns ( user input values which I can not control )
So my question is which function encodes the string value_in_column_1,value_in_column_2,value_in_column_3 to an id of the row?
Example:
jQuery("#" + (rowId) + "_supplier_short_name")[0].value - value found
var rowid = 'j, sdf Ä 34#$'2' 46&&';
jQuery("#" + (rowId) + "_supplier_short_name")[0].value - value NOT found, returns undefined error
regards, Tomaž
04:10

10/08/2009

- You choose on the server side ids of the rows in a complex way and the values have special characters
- The dataUrl of the 'category_entity_id' column should contain the value from the 'supplier_short_name' column from the same row.
To the first problem. It is bad if you use complex method to build rowIds and it is very bad if they have come exotic characters. You should understand that rowIds will be used as ids of HTML elements of row (<tr> elements). A lot of code can work incorrect if you place any characters inside the id. For example if you have "bla td" as id and inside of jqGrid code will be used jQuery('#'+ rowId) then one receive jQuery('#bla td') which will be interpret as selector of td element which is child of the element with id 'bla'. jqGrud try to eliminate some problems with special characters in rowIds normalizing ids with respect of $.jgrid.jqID function, but it solve not all possible problems. So
- make a simple ids
- if you have two grids on the same page don't use the same ids
- don't use for other elements on the page the same ids which could be returned from the server as rowIds
To your main problem. It seems that your problem is not so difficult to solve. Somewhere, typically inside of onSelectRow or ondblClickRow, so you have rowId, you call editRow function. I suggest that before the call of editRow you change dataUrl of the 'category_entity_id' column. Let us the column 'category_entity_id' has index i_category_entity_id (it seems 1 in your colModel). You can do something like following
var myGrid = jQuery("#link_categories");
var newUrl = 'link_categories.php?oper=grid_lookup_category_entity_id&value=' +
encodeURIComponent(myGrid.getCell(rowId,'supplier_short_name'));
var cm = myGrid.getGridParam("colModel");
jQuery.extend(cm[i_category_entity_id], { editoptions: {dataUrl: newUrl}});
Best regards
Oleg
03:53

09/03/2010


I am not sure that I full understand what you want. So I write two main problems which I see
- You choose on the server side ids of the rows in a complex way and the values have special characters
- The dataUrl of the 'category_entity_id' column should contain the value from the 'supplier_short_name' column from the same row.
Yes you are correct, that was my probem, but thanks to you it is almost solved
- make a simple ids
- if you have two grids on the same page don't use the same ids
- don't use for other elements on the page the same ids which could be returned from the server as rowIds
Make simple ids – of course I don't know why I was thinking that id of row must be made from columns which are unique in sql table.
( This is my first javascript/jquery/jqgrid program, so maby to much information at once
To your main problem. It seems that your problem is not so difficult to solve. Somewhere, typically inside of onSelectRow or ondblClickRow, so you have rowId, you call editRow function. I suggest that before the call of editRow you change dataUrl of the 'category_entity_id' column. Let us the column 'category_entity_id' has index i_category_entity_id (it seems 1 in your colModel). You can do something like following
var myGrid = jQuery("#link_categories");
var newUrl = 'link_categories.php?oper=grid_lookup_category_entity_id&value=' +
encodeURIComponent(myGrid.getCell(rowId,'supplier_short_name'));
var cm = myGrid.getGridParam("colModel");jQuery.extend(cm[i_category_entity_id], { editoptions: {dataUrl: newUrl}});
I tryed suggested code but it is returning error: i_category_entity_id is not defined. Even if index is changet to category_entity_id so it is the same as column name, the same type of error is shown. Definition of the column is
edittype:"select",index:'i_category_entity_id'…
I also tryed to put the code below to onSelectRow event (before I call editRow) and dataEvent type 'click', but despite the fact, that dropdown is filled correctly, the value in column is reseted to the first value in select.
Example: drop down values are 1,2 and 3. Current value is set to 3, but when row goes into edit mode the value is reseted to 1 (because 1 in the first place of dropdown menu)
var supplier_short_name = $("#link_categories").jqGrid('getCell',rowId,'supplier_short_name')
$.get('link_categories.php?oper=grid_lookup_category_entity_id&value='+supplier_short_name
,function(data){
var res = $(data).html();
$("#"+ rowid +"_category_entity_id").html(res);
// $("#category_entity_id").html(res);
}
);
Belo is the whole code:
// We use a document ready jquery function.
jQuery(document).ready(function(){
var lastsel;
jQuery("#link_categories").jqGrid({
url:'link_categories.php?nd='+new Date().getTime()+'&grid_name=link_categories',
editurl: "link_categories.php",
onSelectRow: function(rowId){
if(rowId && rowId!==lastsel){
jQuery('#link_categories').jqGrid('saveRow',lastsel);
var myGrid = jQuery("#link_categories");
var newUrl = 'link_categories.php?oper=grid_lookup_category_entity_id&value=' +
encodeURIComponent(myGrid.getCell(rowId,'supplier_short_name'));
var cm = myGrid.getGridParam("colModel");
jQuery.extend(cm[i_category_entity_id], { editoptions: {dataUrl: newUrl}});
jQuery('#link_categories').jqGrid('editRow',rowId,true);
lastsel=rowId;
}
},
datatype: "json",
colModel:[
{name:'supplier_short_name', index:'supplier_short_name',
editable: true, width:120, resizable:true, sorttype:"text", // formatter:'select',
edittype:"select", editrules:{required:true}, formatter:'select',
editoptions:{
value:"1:A;2:B;2:C;4:D",
}
},
{name:'category_entity_id',editable: true, formatter:'select', search: true,
edittype:"select",index:'i_category_entity_id',
editoptions:{
},
dataUrl:'link_categories.php?oper=grid_lookup_category_entity_id',
value: getSequenceNumbers(),
}
},
],
pager: jQuery('#link_categories_footer'),
rowNum:20,
viewrecords: true,
sortorder: "desc",
height: 250,
});
jQuery("#link_categories").jqGrid('filterToolbar');
jQuery("#link_categories").jqGrid('navGrid',"#link_categories_footer",{edit:true,add:true,del:true});
function getSequenceNumbers(){
return "0:ValueA;1:ValueB;2:ValueC;3:ValueE;4:ValueE;5:ValueF;6:ValueG;7:ValueH";
}
});
Regards, Tomaž
10:45

10/08/2009

Hello Tomaž,
in my email I wrote "column 'category_entity_id' has index i_category_entity_id (it seems 1 in your colModel)". You just miss the information. So you should either replace cm[i_category_entity_id] to cm[1]. or define somewhere in your code var i_category_entity_id=1.
Best regards
Oleg
Most Users Ever Online: 715
Currently Online:
90 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