SlickGrid - 选择没有自定义控件的行

时间:2012-01-23 20:20:24

标签: jquery slickgrid

我需要应用程序中的功能,以允许用户单击行来选择行。另外我想为 Ctrl / Shift 添加功能+点击选择一行。

我看到了示例,其中每个行都添加了复选框以选择行。我不希望将这样的复选框添加到应用程序中。

我遇到了一个已有一年的链接但似乎回答了我的问题http://groups.google.com/group/slickgrid/browse_thread/thread/96a5291161d41efa

这里有更好的办法吗?

2 个答案:

答案 0 :(得分:6)

SlickGrid DOM NOT 静态 - 请避免直接修改它。

此功能已通过可插入的SelectionModel内置到SlickGrid中。发行版中包含两个选择模型 - Slick.CellSelectionModel和Slick.RowSelectionModel。您所要做的就是致电

  

grid.setSelectionModel(new Slick.RowSelectionModel());

有关示例,请参阅http://mleibman.github.com/SlickGrid/examples/example9-row-reordering.html

答案 1 :(得分:1)

这是一个83Kb的文件(只是JS),这并不可怕,但对于你想要做的事情来说还是相当大的。

//select the parent table element, then select its child (the `tbody` element) then get its children which will be the `tr` elements
$('table').children().children().on('click', function (event) {

    //check to see if ctrl+shift is being held while this click occured
    if (event.ctrlKey === true && event.shiftKey === true) {

        //if ctrl+shift were held during the click then you know this element has been selected
        //and you can do what you need, in this demo I'm just adding a class to denote that the element has been selected
        $(this).toggleClass('selected');
    }
});

正如您所看到的,如果你想要做的就是测试ctrl+shift在点击tr元素时是否被按下,那么你可以使用少于83KB的代码(上面的代码) demo是600字节)。

以下是演示:http://jsfiddle.net/YZytJ/

请注意,.on()是jQuery 1.7中的新功能,在这种情况下与使用.bind()相同:http://api.jquery.com/on