Jqgrid. Locate rowId from key value

10,995

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 removekey:true` setting.

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.

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.

So if you explain more what you application do and how you use jqGrid I could write you more references.

Share:
10,995
GordonB
Author by

GordonB

Azure fanboy.

Updated on June 04, 2022

Comments

  • GordonB
    GordonB almost 2 years

    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
    

    I want to be able to update a row of data, but need to know the rowId to do so.

    The only data i have is the key value (featureId).

    So i'm looking for a way of finding the rowId based on the primary key value which i do know.

    I've been looking at the jqgrid documentation, and i'm not seeing an obvious way of doing this.


    UPDATE: The answer is to use my table PK as the rowId.

    So, in the add function;

    var RowId = $("#" + jqTableName).jqGrid('getGridParam', 'reccount');
    $("#" + jqTableName).jqGrid('addRowData', RowId, feature);
    

    becomes

    $("#" + jqTableName).jqGrid('addRowData', feature.FeatureId, feature);