Raymond Meade
Raymond Meade

Reputation: 51

using column value in url click event

I've created a grid that lists customer projects and goes to the project's page when you click the row. The problem I'm having is that the grid is passing the rowid instead of the column value that is used in the url parameter so it's pulling up the wrong project. Here is my code:

$(document).ready(function () {
    $("#list").jqGrid({
        url: "getprojects.php",
        datatype: "json",
        mtype: "GET",
        colNames: ["Project ID", "Customer", "Invoice Number", "Vehicle", "Project Date"],
        colModel: [
            {name: "ProjectID", width:60},
            {name: "CustomerName", width:200},
            {name: "InvoiceNumber", width:120},
            {name: "Vehicle", width:220},
            {name: "ProjectDate", width:100}
        ],    
        onSelectRow: function (ProjectID) {
            document.location.href = "manageproject.php?pid=" + ProjectID;
        },    
        pager: "#pager",
        width: 800,
        rowNum: 20,
        rowList: [],
        sortname: "ProjectDate",
        sortorder: "desc",
        height: 'auto',
        viewrecords: true,
        gridview: true,
        caption: ""
    });
});

Upvotes: 0

Views: 129

Answers (1)

Oleg
Oleg

Reputation: 221997

The data returned from the server (from getprojects.php) should contain unique id property, which identify the row and which will be used by jqGrid as the value of id attribute of the row (id of <tr>). If ProjectID contains unique value then you can use jsonReader: { id: "ProjectID" } option to inform jqGrid to use the property as rowid. One more way: you can add key: true property to the definition of the column ProjectID.

If ProjectID column don't contain unique values then you can modify the code of onSelectRow callback to the following:

onSelectRow: function (rowid) {
    var projectID = $(this).jqGrid("getCell", rowid, "ProjectID");
    document.location.href = "manageproject.php?pid=" + encodeURIComponent(projectID);
}

Upvotes: 1

Related Questions