Does anyone know how to get the cells value of the selected row of JQGrid ? i m using mvc with JQGrid, i want to access the value of the hidden column of the selected row ?
是否有人知道如何获取选定行JQGrid的单元格值?我正在使用带有JQGrid的mvc,我想访问所选行的隐藏列的值?
6 个解决方案
#1
83
First you can get the rowid
of the selected row with respect of getGridParam
method and 'selrow' as the parameter and then you can use getCell to get the cell value from the corresponding column:
首先可以得到所选行的rowid,作为参数的是getGridParam方法和selrow,然后可以使用getCell从对应列中获取cell值:
var myGrid = $('#list'),
selRowId = myGrid.jqGrid ('getGridParam', 'selrow'),
celValue = myGrid.jqGrid ('getCell', selRowId, 'columnName');
The 'columnName'
should be the same name which you use in the 'name'
property of the colModel
. If you need values from many column of the selected row you can use getRowData instead of getCell.
“columnName”应该与colModel的“name”属性中使用的名称相同。如果需要从所选行的许多列中获取值,可以使用getRowData而不是getCell。
#2
11
You can use in this manner also
你也可以用这种方式。
var rowId =$("#list").jqGrid('getGridParam','selrow');
var rowData = jQuery("#list").getRowData(rowId);
var colData = rowData['UserId']; // perticuler Column name of jqgrid that you want to access
#3
3
Just to add, you can also retrieve a jqGrid cell value, based on the rowID plus column index (rather than the Column name):
只需添加,您还可以根据rowID +列索引(而不是列名)检索jqGrid单元格值:
So, to fetch the value in the forth column (column index # 3) for the row with primary key ID 1234, we could use this:
因此,要获取第4列(列索引# 3)中主键ID为1234的行中的值,我们可以使用以下方法:
var rowID = 1234;
var columnIndex = 3;
var cellValue = $("#" + rowID).find('td').eq(columnIndex).text();
Btw, on a completely unrelated topic (but please don't vote me down):
顺便说一句,关于一个完全不相关的话题(但请不要投我一票):
I didn't realise that you can, fairly easily, link text boxes to your jqGrid, so your users can do instant searching, without having to open the Search dialog.
我没有意识到,您可以相当容易地将文本框链接到jqGrid,这样您的用户就可以进行即时搜索,而无需打开搜索对话框。
To do this, you need a bit of HTML like this:
要做到这一点,你需要一些像这样的HTML:
<input type="text" name="employeeName" id="employeeName" style="width:250px" />
<!-- This will be my jqGrid control and pager -->
<table id="tblEmployees"></table>
<div id="pager"></div>
And a bit of JavaScript like this:
像这样的JavaScript:
$("#employeeName").on('change keyup paste', function () {
SearchByEmployeeName();
});
function SearchByEmployeeName()
{
// Fetch the text from our <input> control
var searchString = $("#employeeName").val();
// Prepare to pass a new search filter to our jqGrid
var f = { groupOp: "AND", rules: [] };
// Remember to change the following line to reflect the jqGrid column you want to search for your string in
// In this example, I'm searching through the UserName column.
f.rules.push({ field: "UserName", op: "cn", data: searchString });
var grid = $('#tblEmployees');
grid[0].p.search = f.rules.length > 0;
$.extend(grid[0].p.postData, { filters: JSON.stringify(f) });
grid.trigger("reloadGrid", [{ page: 1 }]);
}
This is a real game-changer for me... it really makes jqGrid much more user friendly.
这对我来说是一个真正的游戏规则改变者……它确实使jqGrid对用户友好得多。
Users can immediately start typing in their search string, rather than needing to open the Search dialog, remember to change the operator to "contains", then start typing, and close the search dialog again.
用户可以立即开始输入他们的搜索字符串,而不需要打开搜索对话框,记住要将操作符更改为“contains”,然后开始输入,然后再次关闭搜索对话框。
#4
1
yo have to declarate de vars...
你必须申报……
var selectedRowId = $('#list').jqGrid ('getGridParam', 'selrow');
var columnName = $('#list').jqGrid('getCell', selectedRowId, 'columnName');
var nombre_img_articulo = $('#list').jqGrid('getCell', selectedRowId, 'img_articulo');
var nombre_img_articulo = $(“#列表”)。selectedRowId jqGrid(' getCell ',' img_articulo ');
#5
1
Just Checkout This :
只是付款:
Solution 1 :
解决方案1:
In Subgrid Function You have to write following :
在子网格函数中,你必须写以下内容:
var selectid = $(this).jqGrid('getCell', row_id, 'id');
alert(selectid);
Where row_id
is the variable which you define in subgrid as parameter. And id
is the column name which you want to get value of the cell.
其中row_id是在子网格中定义为参数的变量。id是你想要得到单元格值的列名。
Solution 2 :
解决方案2:
If You Get Jqgrid Row Id In alert Then set your primary key id as key:true
In ColModels. So You will get value of your database id in alert. Like this :
如果您在alert中获得了Jqgrid行Id,那么将主键Id设置为key:true。因此,您将在alert中获取数据库id的值。是这样的:
{name:"id",index:"id",hidden:true, width:15,key:true, jsonmap:"id"},
#6
1
Use "selrow" to get the selected row Id
使用“selrow”获取选定的行Id
var myGrid = $('#myGridId');
var myGrid = $(' # myGridId ');
var selectedRowId = myGrid.jqGrid("getGridParam", 'selrow');
var selectedRowId = myGrid。jqGrid(“getGridParam”、“selrow”);
and then use getRowData to get the selected row at index selectedRowId.
然后使用getRowData在索引selectedRowId上获取选定的行。
var selectedRowData = myGrid.getRowData(selectedRowId);
var selectedRowData = myGrid.getRowData(selectedRowId);
If the multiselect is set to true on jqGrid, then use "selarrrow" to get list of selected rows:
如果在jqGrid中将multiselect设置为true,则使用“selarrrow”获取所选行列表:
var selectedRowIds = myGrid.jqGrid("getGridParam", 'selarrrow');
var selectedRowIds = myGrid。jqGrid(“getGridParam”、“selarrrow”);
Use loop to iterate the list of selected rows:
使用循环迭代所选行列表:
var selectedRowData;
var selectedRowData;
for(selectedRowIndex = 0; selectedRowIndex < selectedRowIds .length;
selectedRowIds ++) {
(selectedRowIndex = 0;selectedRowIndex < selectedRowIds长处;selectedRowIds + +){
selectedRowData = myGrid.getRowData(selectedRowIds[selectedRowIndex]);
}
}
#1
83
First you can get the rowid
of the selected row with respect of getGridParam
method and 'selrow' as the parameter and then you can use getCell to get the cell value from the corresponding column:
首先可以得到所选行的rowid,作为参数的是getGridParam方法和selrow,然后可以使用getCell从对应列中获取cell值:
var myGrid = $('#list'),
selRowId = myGrid.jqGrid ('getGridParam', 'selrow'),
celValue = myGrid.jqGrid ('getCell', selRowId, 'columnName');
The 'columnName'
should be the same name which you use in the 'name'
property of the colModel
. If you need values from many column of the selected row you can use getRowData instead of getCell.
“columnName”应该与colModel的“name”属性中使用的名称相同。如果需要从所选行的许多列中获取值,可以使用getRowData而不是getCell。
#2
11
You can use in this manner also
你也可以用这种方式。
var rowId =$("#list").jqGrid('getGridParam','selrow');
var rowData = jQuery("#list").getRowData(rowId);
var colData = rowData['UserId']; // perticuler Column name of jqgrid that you want to access
#3
3
Just to add, you can also retrieve a jqGrid cell value, based on the rowID plus column index (rather than the Column name):
只需添加,您还可以根据rowID +列索引(而不是列名)检索jqGrid单元格值:
So, to fetch the value in the forth column (column index # 3) for the row with primary key ID 1234, we could use this:
因此,要获取第4列(列索引# 3)中主键ID为1234的行中的值,我们可以使用以下方法:
var rowID = 1234;
var columnIndex = 3;
var cellValue = $("#" + rowID).find('td').eq(columnIndex).text();
Btw, on a completely unrelated topic (but please don't vote me down):
顺便说一句,关于一个完全不相关的话题(但请不要投我一票):
I didn't realise that you can, fairly easily, link text boxes to your jqGrid, so your users can do instant searching, without having to open the Search dialog.
我没有意识到,您可以相当容易地将文本框链接到jqGrid,这样您的用户就可以进行即时搜索,而无需打开搜索对话框。
To do this, you need a bit of HTML like this:
要做到这一点,你需要一些像这样的HTML:
<input type="text" name="employeeName" id="employeeName" style="width:250px" />
<!-- This will be my jqGrid control and pager -->
<table id="tblEmployees"></table>
<div id="pager"></div>
And a bit of JavaScript like this:
像这样的JavaScript:
$("#employeeName").on('change keyup paste', function () {
SearchByEmployeeName();
});
function SearchByEmployeeName()
{
// Fetch the text from our <input> control
var searchString = $("#employeeName").val();
// Prepare to pass a new search filter to our jqGrid
var f = { groupOp: "AND", rules: [] };
// Remember to change the following line to reflect the jqGrid column you want to search for your string in
// In this example, I'm searching through the UserName column.
f.rules.push({ field: "UserName", op: "cn", data: searchString });
var grid = $('#tblEmployees');
grid[0].p.search = f.rules.length > 0;
$.extend(grid[0].p.postData, { filters: JSON.stringify(f) });
grid.trigger("reloadGrid", [{ page: 1 }]);
}
This is a real game-changer for me... it really makes jqGrid much more user friendly.
这对我来说是一个真正的游戏规则改变者……它确实使jqGrid对用户友好得多。
Users can immediately start typing in their search string, rather than needing to open the Search dialog, remember to change the operator to "contains", then start typing, and close the search dialog again.
用户可以立即开始输入他们的搜索字符串,而不需要打开搜索对话框,记住要将操作符更改为“contains”,然后开始输入,然后再次关闭搜索对话框。
#4
1
yo have to declarate de vars...
你必须申报……
var selectedRowId = $('#list').jqGrid ('getGridParam', 'selrow');
var columnName = $('#list').jqGrid('getCell', selectedRowId, 'columnName');
var nombre_img_articulo = $('#list').jqGrid('getCell', selectedRowId, 'img_articulo');
var nombre_img_articulo = $(“#列表”)。selectedRowId jqGrid(' getCell ',' img_articulo ');
#5
1
Just Checkout This :
只是付款:
Solution 1 :
解决方案1:
In Subgrid Function You have to write following :
在子网格函数中,你必须写以下内容:
var selectid = $(this).jqGrid('getCell', row_id, 'id');
alert(selectid);
Where row_id
is the variable which you define in subgrid as parameter. And id
is the column name which you want to get value of the cell.
其中row_id是在子网格中定义为参数的变量。id是你想要得到单元格值的列名。
Solution 2 :
解决方案2:
If You Get Jqgrid Row Id In alert Then set your primary key id as key:true
In ColModels. So You will get value of your database id in alert. Like this :
如果您在alert中获得了Jqgrid行Id,那么将主键Id设置为key:true。因此,您将在alert中获取数据库id的值。是这样的:
{name:"id",index:"id",hidden:true, width:15,key:true, jsonmap:"id"},
#6
1
Use "selrow" to get the selected row Id
使用“selrow”获取选定的行Id
var myGrid = $('#myGridId');
var myGrid = $(' # myGridId ');
var selectedRowId = myGrid.jqGrid("getGridParam", 'selrow');
var selectedRowId = myGrid。jqGrid(“getGridParam”、“selrow”);
and then use getRowData to get the selected row at index selectedRowId.
然后使用getRowData在索引selectedRowId上获取选定的行。
var selectedRowData = myGrid.getRowData(selectedRowId);
var selectedRowData = myGrid.getRowData(selectedRowId);
If the multiselect is set to true on jqGrid, then use "selarrrow" to get list of selected rows:
如果在jqGrid中将multiselect设置为true,则使用“selarrrow”获取所选行列表:
var selectedRowIds = myGrid.jqGrid("getGridParam", 'selarrrow');
var selectedRowIds = myGrid。jqGrid(“getGridParam”、“selarrrow”);
Use loop to iterate the list of selected rows:
使用循环迭代所选行列表:
var selectedRowData;
var selectedRowData;
for(selectedRowIndex = 0; selectedRowIndex < selectedRowIds .length;
selectedRowIds ++) {
(selectedRowIndex = 0;selectedRowIndex < selectedRowIds长处;selectedRowIds + +){
selectedRowData = myGrid.getRowData(selectedRowIds[selectedRowIndex]);
}
}