使用复选框选择数据表行

Datatables row selection with checkbox

提问人:user1592380 提问时间:10/25/2023 更新时间:10/25/2023 访问量:29

问:

enter image description here

我正在使用数据表 1.13.6 和选择插件 1.70 将动态信息加载到数据表中。我正在尝试进行设置,以便行选择基于选中的复选框。但是,尽管选择插件正在工作,但所选内容对应于单击的行,而不是复选框是否被勾选。代码如下:

    const columns = [
      {
        title: "Select",
        data: null,
        orderable: false,
        render: function (data, type, row) {
          if (type === "display") {
            return '<input type="checkbox" class="row-select">';
          }
          return data;
        },
      },
      { title: "listing_id", data: "listing_id" },
      { title: "address", data: "address" },
      { title: "county", data: "county" },
    
   
    ];

    $("#display").DataTable({
      data: treatedData,
      columns: columns,
      order: [[1, "asc"]], // Sorting by the second column (listing_id) by default
      columnDefs: [
        {
          orderable: false,
          className: "select-checkbox",
          targets: 0,
        },
      ],
      select: {
        style: "os",
        selector: "td:first-child",
      },
    });

如何使所选数据与选中的行相对应?

JavaScript jQuery 节点 .js 数据表

评论


答: 暂无答案