Problem getting edited cell value using cell editing events in jqGrid - jqgrid

I've just started using jqGrid and am having a problem trying to get the value of an edited cell when it loses focus. I have a two-column grid with only the first column editable. Eventually my aim is that when the user clicks out of a cell in this column, it will make an Ajax call to the server to populate the second column with a value. Right now, I'm testing by just having the value of the cell displayed in a div on the page. I find the event model very unclear and have tried all the events related to cell editing (beforeEditCell, afterEditCell, beforeSubmitCell, onSubmitCell, etc.) Only the beforeSubmitCell and onSubmitCell events actually return the value. The problem in my test is that when I first edit a cell, the correct value is shown, but when I edit other cells it keeps showing the value and row ID from the first edited cell. Here is my test page: http://www.galcott.com/jqgrid.html where you can see this happening and look at the code.

You have a lot of errors in your code and setup, which causes unexpected behavior.
1.You do not have included one of the important file - the language file. If you have include it you will see where is the problem.
2.You do not have include css framework file, which will cause sometime unexpected behavior.
3.You save a error in the grid parameter cellsubmit - in your code it is cellSubmit, while the working option is cellsubmit - JavaScript is case sensitive
4.At last the event onSubmitCell as I say in my comment should return true or false i.e
onSubmitCell: function(rowid, cellname, value, iRow, iCol) {
$('#celldata').html(iRow + ' ' + value);
if(some condition) {
return false;
}
return true;
}
In your code do:
$("#tbl1").jqGrid({
width: 400,
height: 400,
cellsubmit: 'clientArray',
editurl: 'clientArray',
...
and it will work

Related

jqGrid custom recordtext and using loadComplete to get records count

I am trying to change the recordtext of a display grid to a custom format. I am using a treeview as the selector that refreshes the display grid. I need to find the total records for the grid and I am able to get this value using the getGridParam records method when I click on the treeview node and load the display grid.
However, after I get this value and try to create the custom recordtext, the record count is the previous value, not the current records count. I know that the gridComplete happens before the loadComplete, but even placing the get in the gridComplete and the set int he loadComplete, it still doesn't work, even with a reloadGrid trigger. If I click on the treeview node twice, I get the correct value.
I am thinking it is a timing issue as to when the new value is ready to set the recordtext. Any help would be great, thanks in advance.
I recommend you to try updatepager method, which updates the information on the pager. Alternatively you can do for example the following:
loadComplete: function () {
var p = $(this).jqGrid("getGridParam");
p.records = 123;
p.recordtext = "My View {0} - {1} of <i>{2}<i>";
this.updatepager();
}
to see the viewrecords

JQgrid: Picking the entire row vs clicked cell

Here are two different tables #Oleg made:
On the first one, when clicking a single cell - the entire row is picked.
On the second one, only the clicked cell is picked.
This is being controlled with cellEdit: true.
I'd like to have a logic that will set cellEdit to false, but only for certain rows (under some condition, which for simplicity let's say this will happen when a cell's value is under 100).
How can this be achieved?
To allow to edit data in some column one have to specify editable property in the column. Free jqGrid allows to use callback function as the value of editable property. The callback should return boolean value, which informs jqGrid, whether the cell is editable or not. The wiki article describes the feature more detailed. For example, the following callback in some column colModel allows editing of the cells only if the value in amount column is less as 100:
editable: function (options) {
var item = $(this).jqGrid("getLocalRow", options.rowid);
if (item.amount < 100) {
return false;
}
return true;
}

Fetching jqgrid row on click of hyperlink

I am facing problem in Jqgrid. I have a column with hyperlink and on the click of that hyperlink I want row data. Is this possible using Jqgrid. when I am using "getGridParam" I am getting row id as null.
There are two possibilities you can try here:
1) You can use a custom formatter to create the hyperlink, and have a custom attribute on the link where you put in the rowid (prefix the custom attribute name with 'data-' to keep it html5 compatible). Alternatively you could call a javascript function explicitly passing the row id.
2) Instead of the hyperlink's event itself, try using the onCellSelect event of jqGrid where you get the row and column id of the clicked cell, even if its a hyperlink. But this would trigger the event even if the user clicks anywhere inside the cell, not just on the link!.
I'm sure you found the answer to this by now but for some of you using ASP.NET WebForm here is what I used.
Create the Custom Formatter and add it to the column where you want the link to appear:
My columns are from a database I use a Select statement as so:
switch (jqGrdCol.DataField)
{
case "xxx":
CustomFormatter hypLinkxxx = new CustomFormatter();
hypLinkxxx.FormatFunction = "xxxformatOperations"; --> **JavaScript Function**
jqGrdCol.Formatter.Add(hypLinkxxx);
break;
}
Then in the Javascript function:
function xxxformatOperations(cellvalue, options, rowObject) {
return "<a href=somefile.aspx?xxx=" + rowObject[0] >" + cellvalue + "</font></a>"
}
I get the value of the column as a hyperlink.
I had a similar issue and was did look into your question to figure out a solution and I have found out a solution to this.
The solution is by using onCellSelect: function(rowid, index, contents, event)
this gives the rowid and contents ie the content of the cell you have clicked or selected
therfore you can get the entire row of contents which includes your hyperlink as well

Change value of drop down of specific row in jqGrid

I have created at a table using jqGrid. In that I have a comboBox. I want the values of the combobox such that It is not used in the previous row.
But, once my first row displayed, then I am unable to change the values of comboBoc in the second row.
Ex: In my combobox, there are three values .. one, two, three. I have selected value "two" in the first row. Then the combo box of the second must have two values: one and three.
I have tried the following code:
$("#listData").setColProp('denomination',
{editoptions:{value:getDenominationList('addOperation').toString()}});
Here:
getDenominationList('addOperation') will return a String "1:one;3:three"
But this is not working.
I hope I understand correct your question and you want to change the value parameter of editoptions every time depend on the current row id or other grid contain. You can do this inside your custom dataInit event handler (see editoptions):
dataInit: function (elem) {
var v = $(elem).val();
var rowId = $(e.target).closest('tr.jqgrow').attr('id');
var newValue = getDenominationList('addOperation').toString();
$("#listData").setColProp('denomination', { editoptions: { value:newValue} });
}
The function getDenominationList used in your question don't has the rowid parameter which you probably will need. To simplified it I included in the code above the line which show how the id of the row can be got.
I recommend you to look inside the another answer which I recently answered. It showed how the initial values of value property can be reseted in case of inline editing. It you use form editing you should do this inside of onClose event handler. Moreover in case of form editing you must use recreateForm:true which will force that dataInit event handler will be called not once, but on every row editing.

jqGrid cell editing need to position the error message dialog

I'm using jqGrid with cell editing. I have setup the colModel properties using the editrules option. Everything works fine in that if I edit a cell and try to save an invalid value the grid displays an error dialog, but I need to know how to position the error message dialog that comes up because in the case of my layout it ends up behind a video. I'm not quite sure how to hook into this and there don't seem to be any obvious options on how to do it.
In this case the dialog I would be trying to manipulate is the one with ID of info_dialog.
Also I'm using the clientArray option for cellsubmit.
I realize this is rather old but upon searching I didn't find any indication this might have been added since, so I figured now that I've figured it out I'd let everyone know how I solved the positioning of mine.
$(document).ready(function ()
{
$.jgrid.jqModal = $.extend($.jgrid.jqModal || {}, {
beforeOpen: centerInfoDialog
});
});
function centerInfoDialog()
{
var $infoDlg = $("#info_dialog");
var $parentDiv = $infoDlg.parent();
var dlgWidth = $infoDlg.width();
var parentWidth = $parentDiv.width();
$infoDlg[0].style.left = Math.round((parentWidth - dlgWidth) / 2) + "px";
}
From what I could find in the jqGrid source code, you can add a beforeOpen and an afterOpen. In my case I'd rather position the thing before it's displayed (duh!). Would be nice if there was a parameter to hook it up in the grid declaration, but this does the trick in the mean time.
I hope this helps someone! I spent most of my afternoon on this!
Default value of zIndex parameter of info_dialog is 1000. The function info_dialog from grid.common.js part of jqGrid will be called from grid.celledit.js without usage a 4-th parameter which can change the option.
So the best pragmatical way which I could recomend you is to decrease zIndex value of your div with the video so that it will be less then 1000.

Resources