Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
inline edit and select type
09/09/2010
02:12
Avatar
cyracks
Member
Members
Forum Posts: 5
Member Since:
09/03/2010
sp_UserOfflineSmall Offline

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; 

}); }, }

09/09/2010
19:07
Avatar
cyracks
Member
Members
Forum Posts: 5
Member Since:
09/03/2010
sp_UserOfflineSmall Offline

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:(

09/09/2010
22:17
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

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

10/09/2010
01:49
Avatar
cyracks
Member
Members
Forum Posts: 5
Member Since:
09/03/2010
sp_UserOfflineSmall Offline

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).

colModel:[
{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 rowid = $("#link_categories").jqGrid('getGridParam','selrow');
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

var rowid = $("#link_categories").jqGrid('getGridParam','selrow');
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:

while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$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:

var rowid = 1;
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ž

10/09/2010
04:10
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline
Hi Tomaž,
I am not sure that I full understand what you want. So I write two main problems which I see
  1. You choose on the server side ids of the rows in a complex way and the values have special characters
  2. 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 

11/09/2010
03:53
Avatar
cyracks
Member
Members
Forum Posts: 5
Member Since:
09/03/2010
sp_UserOfflineSmall Offline
Oleg thanks for the help, much appreciated. You probably saved me hours of testing :)
I am not sure that I full understand what you want. So I write two main problems which I see
  1. You choose on the server side ids of the rows in a complex way and the values have special characters
  2. 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

{name:'category_entity_id',editable: true, formatter:'select', search: true, 
      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 rowid = $("#link_categories").jqGrid('getGridParam','selrow');
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ž

11/09/2010
10:45
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

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 

Forum Timezone: Europe/Sofia

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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information