How to find selected ListView Item in Kendo UI DataASource Destroy

676 views Asked by At

I have a KendoUI DataSource

 var myDS = new kendo.data.DataSource({
        transport: {
            read:
            {
                url: getData,
                contentType: 'application/json; charset=utf-8',

            },
            destroy:
            {

                url: deleteData,
                contentType: 'application/json; charset=utf-8',


            },
            parameterMap: function(options, operation) {
                if (operation !== "destroy" && options.models) {
                    return { models: kendo.stringify(options.models) };
                }

            }
        },
        schema: {
            model: {
                id: "Id",
                fields: {
                    Id: { editable: false, nullable: true },
                   name: { type: "string" }

                }
            }
        }

    });

I am binding data source to Kendo ListView as follows

  var listView = $("#alistview").kendoListView({
        dataSource: myDS ,
        template: kendo.template($("#template").html())
    }).data("kendoListView");;

I have created ListView and widget as follows,

  <div id="alistview" style="margin-top:30px"></div>

        <script type="text/x-kendo-tmpl" id="template">
            <div>

                <div>
                    #:name#
                    <a class="k-button k-button-icontext k-delete-button" href="\\#"><span      class="k-icon k-delete"></span></a>

                </div>

            </div>
        </script>
    </div>

On the delete button click the destroy object of KendoUI DataSource is getting called. My question is how to fetch selected item of the ListView in the destroy object of the datasource. For example I want to read name of the selected item when user click on the delete button.

any help ?

1

There are 1 answers

0
Debug_mode On

I got the answer. We can use function in the url instead of the object and inside the function selected item which is calling the destroy can be fetched as follows:

  var myDS= new kendo.data.DataSource({
        transport: {
            read:
            {
                url: getdata,
                contentType: 'application/json; charset=utf-8',

            },
            destroy:
            {
                url: function (appt) { return deteletedata+ "?accountid=" + appt.Id },
                contentType: 'application/json; charset=utf-8',
                //data: {

                //    AccountId: "3"
                //}

            },
            parameterMap: function(options, operation) {
                if (operation !== "destroy" && options.models) {
                    return { models: kendo.stringify(options.models) };
                }

            }
        },
        schema: {
            model: {
                id: "Id",
                fields: {
                    Id: { editable: false, nullable: true },
                    accountname: { type: "string" }

                }
            }
        }

    });