0

我正在使用带有命令按钮的 Bootgrid,如果网格中只有一行(我可以确定 php 中的数据是否只有一行),那么我想触发命令按钮单击事件。命令按钮有一个名为“命令视图”的类。我尝试了以下方法:

$(".command-view").click();

$("#grid .command-view").click();
4

2 回答 2

4

一种更传统的方法是使用内置的 BootGrid 点击处理程序(它基本上是基于行的,如下所示),然后处理之后的点击。

这就是 BootGrid 期望您工作的方式,也意味着您不需要在每一行上放置单独的事件处理程序。

  .on('click.rs.jquery.bootgrid', function (e, cols, row, target) {
     if (typeof row != "undefined")    // Only rows, not headers
     {
         // You will get control here when anything in the row is clicked.
         // In your case just filter for your target and you're done.
     }
于 2016-11-11T12:16:36.080 回答
0

你必须这样做:

var grid = $("#your_grid").bootgrid({
    formatters: {
        "commands": function(column, row)
         {
            return '<button class="command-select"data-row-id='+ row.id +'></button>';
         }
    }
    }).on("loaded.rs.jquery.bootgrid", function () {
        grid.find(".command-select").on("click", function (e) {
            var id = $(this).data("row-id");
            console.log(e)
            console.log(id);
        });
    });

请注意 grid.find 指的是在第一行创建的网格变量。

于 2016-05-10T18:21:45.897 回答