JQGrid:'beforeSelectRow'和'sortableRows'-排除列可拖动吗? [英] JQGrid: 'beforeSelectRow' and 'sortableRows' - exclude column from being draggable?

查看:63
本文介绍了JQGrid:'beforeSelectRow'和'sortableRows'-排除列可拖动吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Oleg

I am using Oleg's suggestion to use the beforeSelectRow event to handle clicks on cells within my grid.

奥列格(Oleg)在他的答案中的代码(完全模仿):

Oleg's code in his answer (which mine exactly mimics):

您可以使用以下按钮来定义列

You can define the columns with buttons like following

{ name: 'add', width: 18, sortable: false, search: false, 
formatter:function(){
    return "<span class='ui-icon ui-icon-plus'></span>"
}}

在上面的代码中,我确实使用了jqGrid的自定义格式化程序,但是没有任何事件绑定.的代码

In the code above I do use custom formatter of jqGrid, but without any event binding. The code of

beforeSelectRow: function (rowid, e) {
        var iCol = $.jgrid.getCellIndex(e.target);
        if (iCol >= firstButtonColumnIndex) {
        alert("rowid="+rowid+"\nButton name: "+buttonNames[iCol]);
    }

    // prevent row selection if one click on the button
    return (iCol >= firstButtonColumnIndex)? false: true;
}

其中firstButtonColumnIndex = 8buttonNames = {8:'Add',9:'Edit',10:'Remove',11:'Details'}.在您的代码中,您可以将警报替换为相应的函数调用.

where firstButtonColumnIndex = 8 and buttonNames = {8:'Add',9:'Edit',10:'Remove',11:'Details'}. In your code you can replace the alert to the corresponding function call.

问题在于我的网格也是可排序的(我在网格上使用了sortableRows方法).如果用户在单击单元格时甚至将鼠标移动了一点,则beforeSelectRow事件将永远不会触发(可排序事件是).

The problem is that my grid is also sortable- (I use the sortableRows method on my grid). If the user is moving the mouse even a little when clicking the cell, the beforeSelectRow event is never triggered (the sortable event is).

在大多数情况下这是理想的-但是,我认为解决此问题的方法是以某种方式排除列作为句柄"以拖动(排序)行并使我的onSelectRow事件在这些列上触发.我只是似乎不知道该怎么做!任何帮助都非常感激:)

This is desirable in most situations- however, I think what would fix this is to somehow exclude columns from being 'handles' to drag (sort) the row and let my onSelectRow event trigger on those columns. I just can't seem to figure out how to do this! Any help is extremely appreciated :)

推荐答案

如果添加以下附加代码,则可以解决此问题

You can fix the problem if you add the following additional code

var grid = $('#list'), tbody = $("tbody:first",grid[0]), ptr, td;
grid.bind('mouseover',function(e) {
    var iCol = $.jgrid.getCellIndex(e.target);
    if (iCol >= firstButtonColumnIndex) {
        tbody.sortable("disable");
    } else {
        tbody.sortable("enable");
    }
});

如果鼠标悬停在动作按钮上,则该代码将禁用jqGrid的可排序功能.因此,您将只能对另一列中的行进行排序.

the code will be disable sortable feature of jqGrid if the mouse will be over the actions buttons. So you will be able to sort the rows only in another column.

您可以在此处看到修改后的演示.

You can see the modified demo here.

这篇关于JQGrid:'beforeSelectRow'和'sortableRows'-排除列可拖动吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆