Jqgrid.从键值中找到rowId [英] Jqgrid. Locate rowId from key value
问题描述
我有一个基本的jqgrid实现.
I've got a basic jqgrid implementation.
$('.fsJqGrid').jqGrid({
datatype: "local",
height: 175,
colNames: ['FeatureId', 'Name', ''],
colModel: [
{ name: 'FeatureId', index: 'FeatureId', width: 75, align: 'left',
sorttype: "int", hidden: true, key: true },
{ name: 'Name', index: 'Name', width: 180 },
{ name: 'tools', index: 'tools', width: 150}
]
});
function FeatGridAddRow(jqTableName, feature) {
///<summary>Adds a row of data to a Feature JQGrid</summary>
var RowId = $("#" + jqTableName).jqGrid('getGridParam', 'reccount');
feature.tools = 'MyToolHtml';
$("#" + jqTableName).jqGrid('addRowData', RowId, feature); //jqgrid
} //function
function FeatGridUpdateRow(featureId, newName) {
///<summary>Updates JQGrid data row</summary>
//I need to find the rowId, based on the featureId parameter
var rowId = 0;
//update grid with new data
$("#tabFS0").jqGrid('setRowData' , rowId , {Name: newName});
} //function
我希望能够更新一行数据,但需要知道rowId才能这样做.
I want to be able to update a row of data, but need to know the rowId to do so.
我仅有的数据是键值(featureId).
The only data i have is the key value (featureId).
所以我正在寻找一种基于我确实知道的主键值查找rowId的方法.
So i'm looking for a way of finding the rowId based on the primary key value which i do know.
我一直在查看jqgrid文档,但没有看到一种明显的方法.
I've been looking at the jqgrid documentation, and i'm not seeing an obvious way of doing this.
因此,在add函数中;
So, in the add function;
var RowId = $("#" + jqTableName).jqGrid('getGridParam', 'reccount');
$("#" + jqTableName).jqGrid('addRowData', RowId, feature);
成为
$("#" + jqTableName).jqGrid('addRowData', feature.FeatureId, feature);
推荐答案
由于您使用key:true
定义了FeatureId
,因此每一行的ID将与FeatureId
列中的值相同.如果您没有t need it you should remove
key:true`设置.
Because you defined FeatureId
with the key:true
, the id of every row will be the same as the value from the FeatureId
column. If you dont need it you should remove
key:true` setting.
您没有发布使用的完整代码示例,所以我想您在将数据填充到jqGrid中的代码位置上遇到了问题.我不会低估您所遇到的情况.从何处接收要填充网格的数据?您一次只收到一行吗?您是从服务器,本地数据源还是从用户输入获取日期?填充行的最有效方法是使用jqGrid的data
参数(请参见
You don't post the full code example which you use, so I suppose you have problem in the place of the code where you to fill the data in the jqGrid. I don't understend the scenario wich you have. From where you receive the data which you want to fill in the grid? Do you receive only one row at once? Do you get the date from the server, from the local data source or from the user input? The most effective way to fill the row is to use data
parameter of the jqGrid (see this answer). Moreover jqGrid has rich possibilities to fill the grid per ajax request.
为了能够回答有关数据编辑的主要问题,您应该描述上下文.您是否需要用户能够修改数据?然后,您可以使用内联编辑,表单编辑或单元格编辑(请参见文档,行编辑"/输入类型"和实时数据操作"/导航器",选择行,然后单击导航器中官方jqGrid演示).如果您要修改未由用户更改的行,则可以使用 setRowData .
To be able to answer on your main question about editing of the data you should describe the context. Do you need that the user are able to modify the data? Then you can use inline editing, form editing or cell editing (see documentation and "Row Editing"/"Input types" and "Live Data Manipulation"/"Navigator", select row and click edit button in the navigator on the official jqGrid demo). If you want to modify the row which are changed not by the user you can use functions like setRowData.
因此,如果您进一步解释应用程序的功能以及jqGrid的使用方式,那么我可以为您提供更多参考.
So if you explain more what you application do and how you use jqGrid I could write you more references.
这篇关于Jqgrid.从键值中找到rowId的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!