最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jqGrid get current rowid - Stack Overflow

programmeradmin1浏览0评论

I have a jgGrid in cellEdit mode. I need to get the current rowid, for some further processing (setting a cell to read-only depending on other values). I cant find a method for that, and the events I've tried does not fire.

The grid definition:

    var curRowId = -1;

    $("#grid").jqGrid({
        datatype: 'json',
        mtype: 'GET',
        colNames: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',],
        colModel: [
          { name: 'a', index: 'a', width: 30, formatter: 'checkbox', edittype: 'checkbox', editable: true },
          { name: 'b', index: 'b', width: 30, formatter: 'checkbox', edittype: 'checkbox', editable: true },
          { name: 'c', index: 'c', width: 70, formatter: 'date', editable: true, editrules: { required: true }, editoptions: { dataInit: function (elem) { $(elem).datepicker(); } } },
          { name: 'd', index: 'd', width: 65, editable: true, formatter: 'date', formatoptions: { srcformat: 'H:i:s', newformat: 'ShortTime' }, editrules: { time: true} },
          { name: 'e', index: 'e', width: 80, edittype: 'select', editable: true, formatter: 'select' },
          { name: 'f', index: 'f', width: 100, editable: true },
          { name: 'g', index: 'g', width: 80, editable: true },
          { name: 'h', index: 'h', width: 80, editable: true, editrules: { maxValue: 50} },
          { name: 'i', index: 'i', width: 120, edittype: 'select', editable: true, formatter: 'select' },
          { name: 'j', index: 'j', width: 200, edittype: 'select', editable: true, formatter: 'select' },
          { name: 'k', index: 'k', width: 70, edittype: 'select', editable: true, formatter: 'select' },
          { name: 'l', index: 'l', width: 70, editable: true, editrules: { maxValue: 10} },
          { name: 'm', index: 'm', width: 25, editable: false },
          { name: 'n', index: 'n', width: 70, editable: true, editrules: { integer: true, maxValue: 999999 }, formatter: formatPosition, unformat: unformatPosition },
          { name: 'o', index: 'o', width: 25, editable: true, editrules: { custom: true, custom_func: chkLongitudTecken} },
          { name: 'p', index: 'p', width: 80, editable: true, editrules: { integer: true, maxValue: 999999 }, formatter: formatPosition, unformat: unformatPosition },
          { name: 'q', index: 'q', width: 80, edittype: 'select', editable: true, formatter: 'select' },
          { name: 'r', index: 'r', width: 100, editable: true, editrules: { maxValue: 50} },
          { name: 's', index: 's', width: 65, edittype: 'select', editable: true, formatter: 'select' },
        ],
        cellEdit: true,
        cellsubmit: "clientArray",
        sortname: 'Datum',
        sortorder: 'desc',
        shrinkToFit: false,
        viewrecords: true,
        gridview: true,
        beforeCellEdit: function (id) {
            curRowId = id;
            alert("Here: " + curRowId);
        },
        onSelectRow: function (id) {
            curRowId = id;
            alert("test: " + curRowId);
        },
        height: 400,
        caption: 'My Cap'
    });

You can see the events I've tried with in the code above.

I need the id so that I later can do something like this:

$("#grid").setColProp("k", {
    editoptions: { 
        value: data.opPadrag,
        dataEvents: [{ 
            type: 'change',
            fn: function (e) {
                alert(e.currentTarget.value);
                $(e).addClass("not-editable-cell");
            }
        }]
    }
});

I have a jgGrid in cellEdit mode. I need to get the current rowid, for some further processing (setting a cell to read-only depending on other values). I cant find a method for that, and the events I've tried does not fire.

The grid definition:

    var curRowId = -1;

    $("#grid").jqGrid({
        datatype: 'json',
        mtype: 'GET',
        colNames: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',],
        colModel: [
          { name: 'a', index: 'a', width: 30, formatter: 'checkbox', edittype: 'checkbox', editable: true },
          { name: 'b', index: 'b', width: 30, formatter: 'checkbox', edittype: 'checkbox', editable: true },
          { name: 'c', index: 'c', width: 70, formatter: 'date', editable: true, editrules: { required: true }, editoptions: { dataInit: function (elem) { $(elem).datepicker(); } } },
          { name: 'd', index: 'd', width: 65, editable: true, formatter: 'date', formatoptions: { srcformat: 'H:i:s', newformat: 'ShortTime' }, editrules: { time: true} },
          { name: 'e', index: 'e', width: 80, edittype: 'select', editable: true, formatter: 'select' },
          { name: 'f', index: 'f', width: 100, editable: true },
          { name: 'g', index: 'g', width: 80, editable: true },
          { name: 'h', index: 'h', width: 80, editable: true, editrules: { maxValue: 50} },
          { name: 'i', index: 'i', width: 120, edittype: 'select', editable: true, formatter: 'select' },
          { name: 'j', index: 'j', width: 200, edittype: 'select', editable: true, formatter: 'select' },
          { name: 'k', index: 'k', width: 70, edittype: 'select', editable: true, formatter: 'select' },
          { name: 'l', index: 'l', width: 70, editable: true, editrules: { maxValue: 10} },
          { name: 'm', index: 'm', width: 25, editable: false },
          { name: 'n', index: 'n', width: 70, editable: true, editrules: { integer: true, maxValue: 999999 }, formatter: formatPosition, unformat: unformatPosition },
          { name: 'o', index: 'o', width: 25, editable: true, editrules: { custom: true, custom_func: chkLongitudTecken} },
          { name: 'p', index: 'p', width: 80, editable: true, editrules: { integer: true, maxValue: 999999 }, formatter: formatPosition, unformat: unformatPosition },
          { name: 'q', index: 'q', width: 80, edittype: 'select', editable: true, formatter: 'select' },
          { name: 'r', index: 'r', width: 100, editable: true, editrules: { maxValue: 50} },
          { name: 's', index: 's', width: 65, edittype: 'select', editable: true, formatter: 'select' },
        ],
        cellEdit: true,
        cellsubmit: "clientArray",
        sortname: 'Datum',
        sortorder: 'desc',
        shrinkToFit: false,
        viewrecords: true,
        gridview: true,
        beforeCellEdit: function (id) {
            curRowId = id;
            alert("Here: " + curRowId);
        },
        onSelectRow: function (id) {
            curRowId = id;
            alert("test: " + curRowId);
        },
        height: 400,
        caption: 'My Cap'
    });

You can see the events I've tried with in the code above.

I need the id so that I later can do something like this:

$("#grid").setColProp("k", {
    editoptions: { 
        value: data.opPadrag,
        dataEvents: [{ 
            type: 'change',
            fn: function (e) {
                alert(e.currentTarget.value);
                $(e).addClass("not-editable-cell");
            }
        }]
    }
});
Share Improve this question edited Feb 8, 2017 at 15:23 Mark Carpenter Jr 8421 gold badge17 silver badges34 bronze badges asked Apr 10, 2012 at 9:05 kazekaze 4,35914 gold badges55 silver badges75 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 11

Found a solution:

var selr = jQuery('#grid').jqGrid('getGridParam', 'selrow');
jQuery('#grid').jqGrid('getGridParam', 'selrow') 

will give the column data as row id used as "key". If the "key" attribute is not set to a particular grid column then the proper row id will be returned.

发布评论

评论列表(0)

  1. 暂无评论