使用Check list kendo Grid的ASP MVC Net

时间:2017-11-20 09:44:45

标签: javascript jquery kendo-ui kendo-grid

如何从kendogrid2获取数据并将其设置为kendogrid1?

我有2个使用清单网格的kendogrid。

这是jquery代码:

public function updateResults($vendors)
{
    try
    {   
        $items = array();
        $sql = "SELECT * FROM collaterals WHERE ";
        foreach ($vendors as $ven)
        {
            echo $ven;
            $sql .= "vendor = ".$ven." OR ";
        }

        $stmt = $this->db->prepare($sql);
        $stmt->execute();

        while($row = $stmt->fetchObject())
        {
            $items[] = $row;
        }

        return $items;

    }
    catch(Exception $e)
    {
        $e->getMessage();
    }
}

如何在 $("#btnAddPortfolio").click(function () { var grid2 = $("#portfolioGrid2").data("kendoGrid"); var dt = grid2.dataItem var ds = new kendo.data.DataSource({ data: [{ "Portfolio": "Data of checklist selected item"}] }); $("#portfolioGrid1").data("kendoGrid").setDataSource(ds); $('#grid2_modal').modal('toggle'); }); 上获取所选项目的价值?

1 个答案:

答案 0 :(得分:1)

实现目标的简单方法:

$("#grid1").kendoGrid({
    dataSource: {
        data: [{ Name: "John Doe" }, { Name: "Jane Doe" }, 
        { Name: "Doe John" }, { Name: "Doe Jane" }]
    },
    columns: [{
        template: '<input type="checkbox" />',
        width: 40
    }, {
        field: "Name"
    }]
});

$("#grid2").kendoGrid({
    columns: [{
        field: "Name"
    }]
});

$("#transfer-items").on("click", function() {
    let grid1 = $("#grid1").data("kendoGrid"),
        grid2 = $("#grid2").data("kendoGrid"),
        $checkboxes = grid1.tbody.find('input:checked').toArray();

    if ($checkboxes.length) {
        $checkboxes.forEach($chk => {
            let item = grid1.dataItem($chk.closest("tr"));
            grid2.dataSource.add(item);
        });
    }
    else {
        window.alert("No item has been selected.");
    }
});

Demo