This is a migrated thread and some comments may be shown as answers.

hidden grid command button reappears when editing another row

3 Answers 618 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 12 Feb 2018, 07:41 PM

I am dynamically hiding a command button on dataBound. When editing I edit that row then switch to another row to edit the hidden button is displayed.

How can I keep this hidden button?

  <script>
                $(document).ready(function () {
                    var crudServiceBaseUrl = "https://demos.telerik.com/kendo-ui/service",
                        dataSource = new kendo.data.DataSource({
                            transport: {
                                read:  {
                                    url: crudServiceBaseUrl + "/Products",
                                    dataType: "jsonp"
                                },
                                update: {
                                    url: crudServiceBaseUrl + "/Products/Update",
                                    dataType: "jsonp"
                                },
                                destroy: {
                                    url: crudServiceBaseUrl + "/Products/Destroy",
                                    dataType: "jsonp"
                                },
                                create: {
                                    url: crudServiceBaseUrl + "/Products/Create",
                                    dataType: "jsonp"
                                },
                                parameterMap: function(options, operation) {
                                    if (operation !== "read" && options.models) {
                                        return {models: kendo.stringify(options.models)};
                                    }
                                }
                            },

                            batch: true,
                            pageSize: 20,
                            schema: {
                                model: {
                                    id: "ProductID",
                                    fields: {
                                        ProductID: { editable: false, nullable: true },
                                        ProductName: { validation: { required: true } },
                                        UnitPrice: { type: "number", validation: { required: true, min: 1} },
                                        Discontinued: { type: "boolean" },
                                        UnitsInStock: { type: "number", validation: { min: 0, required: true } }
                                    }
                                }
                            }
                        });
gridCommands =[{
                        name: "edit",
                        text: " ",
                        mode: "inline"},
                                      {
                          name:"destroy",
                          text: " "},
                                   {
                          name: "exportproduct",
                          text:"Export",
                          click: ExportProduct}
                          ];
                    $("#grid").kendoGrid({
                        dataSource: dataSource,
                        pageable: true,
                        height: 550,
                        toolbar: ["create"],
                        columns: [
                            "ProductName",
                            { field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: "120px" },
                            { field: "UnitsInStock", title:"Units In Stock", width: "120px" },
                            { field: "Discontinued", width: "120px", editor: customBoolEditor },
                            { command: gridCommands, title: "&nbsp;", width: "250px" }],
                        editable: "inline",
                        dataBound: function (e) {
                            var columns = e.sender.columns,
                                dataItems = e.sender.dataSource.view();

                            for (var i = 0; i < dataItems.length; i++) {
                                var product = dataItems[i].get("ProductName");
                                if (product === "Chang") {
                                    var row = e.sender.tbody.find("[data-uid='" + dataItems[i].uid + "']");
                                    var cell = row.children().eq(4);
                                    var btn = cell.children().eq(2);
                                    btn.hide();
                                }

                            }
                     
                       }
                    });
                });

                function customBoolEditor(container, options) {
                    var guid = kendo.guid();
                    $('<input class="k-checkbox" id="' + guid + '" type="checkbox" name="Discontinued" data-type="boolean" data-bind="checked:Discontinued">').appendTo(container);
                    $('<label class="k-checkbox-label" for="' + guid + '"></label>').appendTo(container);
                }
              function ExportProduct(container) {
                alert(container.name);
              }
        </script>

3 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 14 Feb 2018, 04:36 PM
Hi,

I assume that this happens if you open a row or if no saving/updating is performed? Otherwise (edit and save the changes) should re-render the grid and call the dataBound event. Could you please confirm that this behavior or provide a bit more information?  

Regards,
Boyan Dimitrov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Jeff
Top achievements
Rank 1
answered on 14 Feb 2018, 04:44 PM
Correct opening a row for edit that has the button hidden. Then selecting a different row for edit without updating or saving the current row the hidden button will be displayed.
0
Boyan Dimitrov
Telerik team
answered on 15 Feb 2018, 05:12 PM
Hello,

In this case the only solution would be to use the https://docs.telerik.com/kendo-ui/api/javascript/ui/grid/events/edit event as well along with the dataBound event. This will ensure that the code for hiding the buttons will be executed when user switches to edit without to save or cancel the changes from the previous row opened for edit. Speaking of cancel the same logic should be applied in the cancel event handler as well. Same thing happens in case that user clicks on cancel command button - cancel event is triggered, but the dataBound event will not be fired, since no changes are applied to the data items. 

Regards,
Boyan Dimitrov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Jeff
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or