18

i have developed a web application using kendo ui tools and theres a kendo grid with batch edit mode..

but when i press the delete button for any record in kendo grid it will erase from the list in grid but actually not in the data source.when i reload the page or grid the deleted item will still exist..

here is the code of my grid

<div id="grid">
        </div>
        <script type="text/javascript">

            $("#submitMarketUser").click(function () {
                var grid = $("#grid").data("kendoGrid");
                var dataSource = new kendo.data.DataSource({
                    transport: {
                        read: {
                            url: "WholeSaleTrade/GetTradeProductDetail",
                            dataType: "json",
                            data: {
                                test: $("#Names").val()
                            }
                        },
                        destroy: {
                            url: "WholeSaleTrade/DeletePro",
                            type: "POST",
                            dataType: "jsonp",
                            data: {
                                DAKy: $("#Names").val(),
                                DIKy: $("#btntxt").val()
                            }
                        },
                        create: {
                            url: "WholeSaleTrade/CreateProduct",
                            type: "POST",
                            dataType: "jsonp",
                            data: {
                                AKy: $("#Names").val(),
                                IKy: $("#btntxt").val()
                            }
                        }
                    },
                    pageSize: 5,
                    schema: {
                        model: {
                            id: "ProductKey",
                            fields: {
                                ProductKey: { editable: false, nullable: true },
                                ProductName: { validation: { required: true} }
                            }
                        }
                    }
                });
                $("#grid").kendoGrid({
                    dataSource: dataSource,
                    editable: true,
                    toolbar: ["create", "save"],
                    autobind: true,
                    pageable: true,
                    columns: [
                        { field: "ProductName", title: "Product Name",
                            editor: function (container, options) {
                                var model = options.model;
                                $('<input id="btntxt" name="' + options.field + '"/>').appendTo(container).kendoComboBox({
                                    dataSource: {
                                        type: "POST",
                                        transport: {
                                            read: {
                                                url: "MarketInformation/PopulateProducts",
                                                success: function (data) {
                                                    var prod = data[0];
                                                    model.set("ProductName", prod.ItmNm);
                                                    model.set("ItmKy", prod.ItmKy);
                                                    model.set("UserKey", $("#Names").val());
                                                }
                                            }
                                        }
                                    },

                                    dataValueField: "ItmKy",
                                    dataTextField: "ItmNm"
                                });
                            }
                        },
                        { command: ["destroy"], title: "&nbsp;" }
                    ]
                });
            });

        </script>

can not identify that where is the fault going and can somebody please help me to solve this matter.

Iman Mahmoudinasab
  • 6,861
  • 4
  • 44
  • 68
sanzy
  • 805
  • 9
  • 18
  • 28
  • Did you check if you have any error in the browser console? – OnaBai Jul 09 '13 at 08:18
  • Do you use Firebug or similar? Does it show any error while executing your javascript. I've tried your code and it worked but of course I've done some modification since I do not have all your project. – OnaBai Jul 09 '13 at 09:59
  • then can you please send me your modifications please.. – sanzy Jul 09 '13 at 10:53
  • yes i cheked wit firebug and it will not fire the method that used to delete the record in controller.. that is the problem – sanzy Jul 09 '13 at 11:15
  • 1
    Did you click on "Save changes"? – OnaBai Jul 09 '13 at 12:08
  • yes i cheked with "Save Changes"..it show as record deleted when i press "Save changes" but on page refresh or grid reload, record is still there.. that is the problem. – sanzy Jul 10 '13 at 02:33
  • Was my answer useful sanzy? – Myzifer Jul 25 '13 at 14:59
  • Bug 2.0, hello sanzy I'm asking for a response. – Myzifer Jul 26 '13 at 11:19
  • So any progress or...? – Myzifer Jul 29 '13 at 08:08
  • sanzy is there any reason why your ignoring me as I'd just like to know if my answer solved the issue (and then get it marked as correct) or if you resolved it by other means in which case I'd still be interested to find out how so I could improve my own knowledge. – Myzifer Jul 30 '13 at 08:01
  • @Myzifer i'm extremely sorry for couldn't response to your answer because i was not there due to another reason.. just went through your answer and it will not give me the positive feedback. – sanzy Aug 05 '13 at 02:47
  • I also noticed in your other commands you set the datatype as jsonp which shouldn't be changed from just simply json so if you change that back and remove the type Post then that should work. – Myzifer Aug 05 '13 at 08:15
  • @Myzifer ok sir.. il check and let you know whether it is helped or not.. thank you anyway.. – sanzy Aug 07 '13 at 05:42
  • @sanzy have you checked my answer? I hope it help you and others who refers later. and answer your not answered question after 6 month. – Iman Mahmoudinasab Jan 30 '14 at 08:59

5 Answers5

44

There are three common reasons delete won't work:


1. Not setting editable of grid to inline or popup. The deleted items will be automatically processed through transport destroy only for "inline"/"popup" edit modes. Ex:

editable: {
   mode: "inline",
}
//or
editable: "inline"


2. If on your datasource, you have the batch flag set to true, this means the datasource will make the call only after you tell it to, e.g calling sync(). Ex:

var dataSource = new kendo.data.DataSource({
    batch: true,
    //.....
});
//... in some where e.g in a save button click event call the following line:
dataSource.sync();


3. You should define id to your primary key of database field name inside model of datasource. Ex:

   model: {
        id: "ProductID",
        fields: {
            ProductID: { editable: false, nullable: true },
        }
    }


So the problem with your code is first one, i.e you did not set editable to inline or popup
Iman Mahmoudinasab
  • 6,861
  • 4
  • 44
  • 68
3

If you choose not to include editable.mode in order to utilize the in-cell editing, you can set the toolbar of the grid to include the option save:

$("#grid").kendoGrid({
    dataSource: {
        transport: {
            ....
        },
        schema: {
            ....
        }
    },                        
    toolbar: ["create", "save", "cancel"],
    columns: [
        ....
    ],
    editable: true
});

This will create a save button at the toolbar of the grid. After deleting any records by clicking the destroy command button, click on the save button to have the grid to make an Ajax call to the server to delete the record.

If you would rather delete the record automatically without including the save button, you could add a change event handler to the datasource of the grid:

$("#grid").kendoGrid({
    dataSource: {
        transport: {
            ....
        },
        schema: {
            ....
        },
        change: function(e) {
            if (e.action === "remove") {
                this.sync();
            }
        }
    },                        
    columns: [
        ....
    ],
    editable: true
});

This will automatically sync the changes you made to the grid with the server when there's a data change.

Twisted Whisper
  • 1,166
  • 2
  • 15
  • 27
0

Hmm try not including type: "POST", and see if it now works since as far as I can see that bit isn't included on the demo's and I don't think I included it when I last did inline edits/deletes.

Myzifer
  • 1,116
  • 1
  • 20
  • 56
0

I had put an arbitray name for an int on the server Delete Method.

    [HttpPost]
    public ActionResult DeleteRandomTest(Int32 randomTestId)
    {
         ...
    }

The default modelbinder was probably looking for a property called Id (same as the primary key of my type according to the configuration of the model).

 .Model(config => config.Id(p => p.Id))

In fact, I proved this by changing the signature to the following:

    [HttpPost]
    public ActionResult DeleteRandomTest(Int32 Id)
    {
        ...
    }

My break point was hit after that.

Ultimately, I used the full type as the parameter as shown in the Kendo examples because I didn't want to have poorly named parameter names (not camel case) in the action. Shown as follows:

    [HttpPost]
    public ActionResult DeleteRandomTest([DataSourceRequest]
         DataSourceRequest request, RandomDrugTest randomDrugTest)
    {
       ...
    }

This seems to the be the reason it wasn't working.

jwize
  • 4,230
  • 1
  • 33
  • 51
0

I had the same issue. My issue was caused by having a data property in the kendo model. Example:

{id: 1, data: ""}
Jakobovski
  • 3,203
  • 1
  • 31
  • 38