【问题标题】:onSelectRow in a JQGridJQGrid 中的 onSelectRow
【发布时间】:2014-07-24 14:54:45
【问题描述】:

我已经完成了针对无法在 SelectRow 上工作但它们无法为我工作的解决方案。

我有以下代码:

$("#myActions_gridTable").jqGrid({
        datatype:'local',
        data: myActionsData,
        cellsubmit: 'clientArray',
        cellEdit: true,
        rowNum: noOfLinesToDisplay,
        pager: $("#myActions_pager"),
        sortname: 'contract_Name',
        viewrecords: true,
        sortorder: 'asc',
        autoWidth:true,
        loadonce: true,
        cmTemplate: { title: false },
        height:'auto',
        scrollrows: true,
        colNames:["id","Status"],
        colModel:[
            {
                name:'id',index:'id', jsonmap:'id', width:1,hidden:true,key:true, editable:true
            },

            {name:'status',index:'status', align:'center', sortable: false,
                editable: true,
                edittype: "select",
                width: 150,
                editoptions: {
                    value: "1:Done;2:Running"
                }

            }
        ],


        onSelectRow : function(id){ 
            console.log('inside onSelectRow');
            if (id && id !== lastsel) {
                $('#myActions_gridTable').restoreRow(lastsel);
                $('#myActions_gridTable').editRow(id, true);
                lastsel = id;
            }

        }
    });

这里 OnSelectRow 不会被触发,也不会打印 console.log。 请帮忙。

【问题讨论】:

  • 奇怪的是你同时使用了cellEdit: trueeditRow(在onSelectRow 内部)。你想实现哪个editing mode:单元格编辑还是行编辑?你定义了lastsel 变量吗?
  • trirand.com/jqgridwiki/doku.php?id=wiki:events 这里的“S”是变量名“lastSel”的大写,这可能是一个原因。您是否发现任何浏览器控制台错误?
  • 我不认为这与变量名问题有关.. @BhushanKawadkar
  • @Oleg 没有什么对我有用,所以我只是尝试添加 cellEdit 也是如此。
  • @p.pradnya:您能否将您使用的输入数据包括在内。我觉得奇怪的是您使用edittype: "select"editoptions: {value: "1:Done;2:Running"} 而没有 使用formatter: "select"。您在输入数据中使用"Done""Running" 字符串还是12

标签: javascript jquery jqgrid jquery-events jqgrid-formatter


【解决方案1】:

需要将变量lastsel定义为

 var lastsel;

在上面的代码中你需要做的:

var lastsel;
$("#myActions_gridTable").jqGrid({
..............
..............
..............,
  onSelectRow : function(id){ 
                        console.log('inside onSelectRow');
                        if (id && id !== lastsel) {
                            $('#myActions_gridTable').restoreRow(lastsel);
                            $('#myActions_gridTable').editRow(id, true);
                            lastsel = id;
                        }

                    }

这是工作的JsFiddle Demo

并且可以在这里http://www.trirand.com/jqgridwiki/doku.php?id=wiki:events获得更多信息。

【讨论】:

  • 我已经声明了 lastsel 变量,所以这不是问题
【解决方案2】:

一个可能的问题是使用edittype: "select" 没有使用formatter: "select"。无论如何,如果您不使用formatter: "select",我似乎非常怀疑editoptions: { value: "1:Done;2:Running" } 的属性。

"status" 列的输入数据看起来如何?您使用12 还是"Done""Running"?如果你想在数据中保存12 值,但你想将值显示为"Done""Running",那么你应该使用

formatter: "select", edittype: "select", editoptions: {value: "1:Done;2:Running"}

The demo 演示了它。它使用

var myActionsData = [
        { id: 10, status: 1 },
        { id: 20, status: 2 }
    ];

作为输入。

也可以使用

var myActionsData = [
        { id: 10, status: "Done" },
        { id: 20, status: "Running" }
    ];

但应该使用

edittype: "select", editoptions: {value: "Done:Done;Running:Running"}

在这种情况下。在最后一种情况下不需要formatter: "select":请参阅another demo

【讨论】:

    【解决方案3】:

    cellEdit 为真时,OnSelectrow 不起作用。

    您可以使用onCellSelect 代替OnSelectrow

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多