2

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);
GordonBy
  • 3,099
  • 6
  • 31
  • 53

1 Answers1

3

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.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • I'm adding data one line at a time using the FeatGridAddRow function. I've created the FeatGridUpdateRow function to illustrate the what i'm trying to do. I don't want to use inline editing. I'm using my own popup mechanism for allowing the user to make their own changes, i just need a way of locating the correct row in order to make their changes visible. – GordonBy Dec 10 '10 at 15:24
  • @GordonB: I don't understand how you want to integrate your "own popup mechanism" in jqGrid, so it is difficult to give you advises. Probably `$("#list").jqGrid('getGridParam', 'selrow')` - the id of currently selected row would be what you need. If you do prefer identify the rows per `featureId` why you not add the rows using the `featureId` as rowid? Why you use the value of the 'reccount' instead? – Oleg Dec 10 '10 at 15:55
  • @GordonB: By the way, you can remove `align:'left'` and `multiselect: false` because it's default settings. You should also remove comma before "});" at the end of the jqGrid definition. – Oleg Dec 10 '10 at 16:05
  • I'm using my own mechansim for the editing as it's the interface i want my users to use, i just plain don't want to be forced into using the jqgrid edit interface. This shouldn't be a problem. – GordonBy Dec 10 '10 at 16:32
  • "why you not add the rows using the featureId as rowid" probably helps me out the most here. stray comma's are just a result of the hacking of my working example for SO. – GordonBy Dec 10 '10 at 16:32