jqGrid inline delete: selected row "selrow" is incorrect - jqgrid

I have a in-line delete button, I want to append more data to the delete message pop-up like this:
"Delete selected row with code = 7 ?"
I'm using the following in the delOptions:
beforeShowForm: function ($form) {
var sel_id = $("#list").jqGrid('getGridParam', 'selrow');
$("td.delmsg", $form[0]).html("Delete record with <b>code=" + $("#list").jqGrid('getCell', sel_id, 'cd') + "</b>?");}
The problem is If I click on the delete button without first clicking on any part of the row, the selrow is either null or it gets the previously selected row not the currently selected!
How do I make the row selected when clicking on the trash bin icon?
Any help is appreciated

I suppose that you use the example which I posted in the old answer. It was written in case of usage of the Delete button (the part of form editing) from navigator bar.
There are one hidden row in the Delete dialog which could help you. Try this one
beforeShowForm: function ($form) {
// get comma separated list of ids of rows which will be delete
// in case of multiselect:true grid or just id of the row.
// In the code below we suppose that single row selection are used
var idOfDeletedRow = $("#DelData>td:nth-child(1)").text();
$form.find("td.delmsg").eq(0)
.html("Delete record with <b>code=" +
$(this).jqGrid('getCell', idOfDeletedRow, 'cd') + "</b>?");
// REMARK: in old versions of jqGrid you can't use $(this) and
// will have to use something like $("#list")
}

Related

RadGrid EditColumn Insert Data to an Edit Field from a RadGrid in a RadWindow

I have a telerik:RadGrid that contains Bound Data,
I am calling Popup Edit Control Of RadGrid, I am getting all the fields and edit works fine.
What I want to do is from the Edit Popup, Edit one of the fields (Which is a RadTextBox) by clicking a button to open a RadWindow, this Window Contains another RadGrid with user details and one of the column with a button that executes RadGrid_OnCommand event, I am passing one of the values of the Grid by:
CommandArguments='<%# Eval("UserName")%>'
How can I place this value to the RadTextBox.Text in the Edit PopUp, So that I can update the grid with the selected value?
I would really appreciate any help. Thank you in Advance
I solved the issue by geting the grid row, which is in edit mode so I got the value of which row I need to change and updated its Editible item by ID using this code:
var rowid = RadGrid1.EditIndexes[RadGrid1.EditIndexes.Count-1];
GridEditFormItem rowEditControls;
foreach (GridDataItem row in RadGrid1.Items)
{
if (row.ItemIndex == int.Parse(rowid))
{
rowEditControls = row.EditFormItem;
((rowEditControls as GridEditableItem).FindControl("ID") as RadTextBox).Text = e.CommandArgument.ToString();
}
}
I Hope this will be helpfull for someone, I find it valuable for customising your edit forms.

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

JQGrid Delete Row Does Not Delete Subgrid

I delete a row in a jqGrid like so:
elem.jqGrid('delRowData', rowid);
But the subgrid associated to this row remains. What other clever thing do I need to do to make the whole row (including subgrid) go away?
You can do instead of the code which you posted the following:
var selRow = $('#'+rowid), // get the row (<tr> element having id=rowid)
nextRow = selRow.next(); // get the next row
if (nextRow.hasClass('ui-subgrid')) {
// if the next row is a subgrid one should remove it
nextRow.remove();
}
elem.jqGrid('delRowData', rowid);
// the call of delRowData is better as just selRow.remove();
// because it change "records" and "reccount" parameters and
// change parameters "selrow" and "selarrrow" in case that
// the deleted row was selected.
This seems to work:
elem.jqGrid('collapseSubGridRow', rowid);
elem.jqGrid('delRowData', rowid);
Umm, okay.

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 : specific value from a selected row

how to get a value of a (hidden) column, from the selected row. that is, the cell value needs to be from the cell identied by colName, and the selected row (not using multi select). From the API i see the method getGridParam("selrow") for reading the row, may be able to combine with other methods.. but, any convenient method available? a code snippet would save lot of time... \
thanks.
You should use getCell function to read the value from the cell identified by row id. So if you need a data from the column 'MyColName' of selected row you can do this with the following code:
var grid = jQuery('#list');
var sel_id = grid.jqGrid('getGridParam', 'selrow');
var myCellData = grid.jqGrid('getCell', sel_id, 'MyColName');
If you need read full data of a row you can use getRowData instead of getCell. More about methods supported by jqGrid you can read in the documentation (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods).

Resources