0

How to get data from kendogrid2 and set it to kendogrid1?

I have the 2 kendogrid using checklist grid.

This is the jquery code:

 $("#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');  
        });

How to get the value of selected item on #portofolioGrid2?

1 Answer 1

1

A simple way to achieve it:

$("#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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.