Stop detailInit collapse when adding a new row to the grid?












0















I have a grid that has a grid in the detailInit and when I add a new row to the grid in the detailInit the detailInit collapses.



How can I stop it from collapsing when a new record is added? I have tried using e.preventDefault() on the button click event of adding a new row but that didn't work out.










share|improve this question



























    0















    I have a grid that has a grid in the detailInit and when I add a new row to the grid in the detailInit the detailInit collapses.



    How can I stop it from collapsing when a new record is added? I have tried using e.preventDefault() on the button click event of adding a new row but that didn't work out.










    share|improve this question

























      0












      0








      0








      I have a grid that has a grid in the detailInit and when I add a new row to the grid in the detailInit the detailInit collapses.



      How can I stop it from collapsing when a new record is added? I have tried using e.preventDefault() on the button click event of adding a new row but that didn't work out.










      share|improve this question














      I have a grid that has a grid in the detailInit and when I add a new row to the grid in the detailInit the detailInit collapses.



      How can I stop it from collapsing when a new record is added? I have tried using e.preventDefault() on the button click event of adding a new row but that didn't work out.







      kendo-ui kendo-grid






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jul 1 '18 at 19:43









      ChrisChris

      1,11052161




      1,11052161
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You cannot prevent it from collapsing because every time you change something to the data it automatically rebinds and redraw the table.



          What you can do however is to capture the rebinding, find the opened details and after the binding finish reopen them:






          <!DOCTYPE html>
          <html>
          <head>
          <meta charset="utf-8"/>
          <title>Kendo UI Snippet</title>

          <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.common.min.css"/>
          <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.rtl.min.css"/>
          <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.silver.min.css"/>
          <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.mobile.all.min.css"/>

          <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
          <script src="https://kendo.cdn.telerik.com/2018.3.1017/js/kendo.all.min.js"></script>
          </head>
          <body>

          <div id="example">
          <div id="grid"></div>

          <script>
          let data = [{id: 1, FirstName: "Nancy", LastName: "Davolio", orders: [{title: 1}, {title: 2}]}];

          $(document).ready(function () {
          let expanded = ;

          var element = $("#grid").kendoGrid({
          dataSource: data,
          toolbar: [{name: "create"}],
          height: 600,
          detailInit: detailInit,
          editable: true,
          columns: [
          {
          field: "id",
          title: "id",
          },
          {
          field: "FirstName",
          title: "First Name",
          width: "110px"
          },
          {
          field: "LastName",
          title: "Last Name",
          width: "110px"
          },
          {command: ["destroy"]},
          ],
          dataBinding: function (e) {
          expanded = $.map(this.tbody.children(":has(> .k-hierarchy-cell .k-i-collapse)"), function (row) {
          return $(row).data("uid");
          });
          },
          dataBound: function (e) {
          this.expandRow(this.tbody.children().filter(function (idx, row) {
          return $.inArray($(row).data("uid"), expanded) >= 0;
          }));
          },
          });

          });

          function detailInit(e) {
          $("<div/>").appendTo(e.detailCell).kendoGrid({
          dataSource: {
          transport: {
          read: function (options) {
          options.success(e.data.orders);
          },
          }
          },
          });
          }
          </script>
          </div>
          </body>
          </html>








          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51126488%2fstop-detailinit-collapse-when-adding-a-new-row-to-the-grid%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You cannot prevent it from collapsing because every time you change something to the data it automatically rebinds and redraw the table.



            What you can do however is to capture the rebinding, find the opened details and after the binding finish reopen them:






            <!DOCTYPE html>
            <html>
            <head>
            <meta charset="utf-8"/>
            <title>Kendo UI Snippet</title>

            <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.common.min.css"/>
            <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.rtl.min.css"/>
            <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.silver.min.css"/>
            <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.mobile.all.min.css"/>

            <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
            <script src="https://kendo.cdn.telerik.com/2018.3.1017/js/kendo.all.min.js"></script>
            </head>
            <body>

            <div id="example">
            <div id="grid"></div>

            <script>
            let data = [{id: 1, FirstName: "Nancy", LastName: "Davolio", orders: [{title: 1}, {title: 2}]}];

            $(document).ready(function () {
            let expanded = ;

            var element = $("#grid").kendoGrid({
            dataSource: data,
            toolbar: [{name: "create"}],
            height: 600,
            detailInit: detailInit,
            editable: true,
            columns: [
            {
            field: "id",
            title: "id",
            },
            {
            field: "FirstName",
            title: "First Name",
            width: "110px"
            },
            {
            field: "LastName",
            title: "Last Name",
            width: "110px"
            },
            {command: ["destroy"]},
            ],
            dataBinding: function (e) {
            expanded = $.map(this.tbody.children(":has(> .k-hierarchy-cell .k-i-collapse)"), function (row) {
            return $(row).data("uid");
            });
            },
            dataBound: function (e) {
            this.expandRow(this.tbody.children().filter(function (idx, row) {
            return $.inArray($(row).data("uid"), expanded) >= 0;
            }));
            },
            });

            });

            function detailInit(e) {
            $("<div/>").appendTo(e.detailCell).kendoGrid({
            dataSource: {
            transport: {
            read: function (options) {
            options.success(e.data.orders);
            },
            }
            },
            });
            }
            </script>
            </div>
            </body>
            </html>








            share|improve this answer




























              0














              You cannot prevent it from collapsing because every time you change something to the data it automatically rebinds and redraw the table.



              What you can do however is to capture the rebinding, find the opened details and after the binding finish reopen them:






              <!DOCTYPE html>
              <html>
              <head>
              <meta charset="utf-8"/>
              <title>Kendo UI Snippet</title>

              <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.common.min.css"/>
              <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.rtl.min.css"/>
              <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.silver.min.css"/>
              <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.mobile.all.min.css"/>

              <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
              <script src="https://kendo.cdn.telerik.com/2018.3.1017/js/kendo.all.min.js"></script>
              </head>
              <body>

              <div id="example">
              <div id="grid"></div>

              <script>
              let data = [{id: 1, FirstName: "Nancy", LastName: "Davolio", orders: [{title: 1}, {title: 2}]}];

              $(document).ready(function () {
              let expanded = ;

              var element = $("#grid").kendoGrid({
              dataSource: data,
              toolbar: [{name: "create"}],
              height: 600,
              detailInit: detailInit,
              editable: true,
              columns: [
              {
              field: "id",
              title: "id",
              },
              {
              field: "FirstName",
              title: "First Name",
              width: "110px"
              },
              {
              field: "LastName",
              title: "Last Name",
              width: "110px"
              },
              {command: ["destroy"]},
              ],
              dataBinding: function (e) {
              expanded = $.map(this.tbody.children(":has(> .k-hierarchy-cell .k-i-collapse)"), function (row) {
              return $(row).data("uid");
              });
              },
              dataBound: function (e) {
              this.expandRow(this.tbody.children().filter(function (idx, row) {
              return $.inArray($(row).data("uid"), expanded) >= 0;
              }));
              },
              });

              });

              function detailInit(e) {
              $("<div/>").appendTo(e.detailCell).kendoGrid({
              dataSource: {
              transport: {
              read: function (options) {
              options.success(e.data.orders);
              },
              }
              },
              });
              }
              </script>
              </div>
              </body>
              </html>








              share|improve this answer


























                0












                0








                0







                You cannot prevent it from collapsing because every time you change something to the data it automatically rebinds and redraw the table.



                What you can do however is to capture the rebinding, find the opened details and after the binding finish reopen them:






                <!DOCTYPE html>
                <html>
                <head>
                <meta charset="utf-8"/>
                <title>Kendo UI Snippet</title>

                <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.common.min.css"/>
                <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.rtl.min.css"/>
                <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.silver.min.css"/>
                <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.mobile.all.min.css"/>

                <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
                <script src="https://kendo.cdn.telerik.com/2018.3.1017/js/kendo.all.min.js"></script>
                </head>
                <body>

                <div id="example">
                <div id="grid"></div>

                <script>
                let data = [{id: 1, FirstName: "Nancy", LastName: "Davolio", orders: [{title: 1}, {title: 2}]}];

                $(document).ready(function () {
                let expanded = ;

                var element = $("#grid").kendoGrid({
                dataSource: data,
                toolbar: [{name: "create"}],
                height: 600,
                detailInit: detailInit,
                editable: true,
                columns: [
                {
                field: "id",
                title: "id",
                },
                {
                field: "FirstName",
                title: "First Name",
                width: "110px"
                },
                {
                field: "LastName",
                title: "Last Name",
                width: "110px"
                },
                {command: ["destroy"]},
                ],
                dataBinding: function (e) {
                expanded = $.map(this.tbody.children(":has(> .k-hierarchy-cell .k-i-collapse)"), function (row) {
                return $(row).data("uid");
                });
                },
                dataBound: function (e) {
                this.expandRow(this.tbody.children().filter(function (idx, row) {
                return $.inArray($(row).data("uid"), expanded) >= 0;
                }));
                },
                });

                });

                function detailInit(e) {
                $("<div/>").appendTo(e.detailCell).kendoGrid({
                dataSource: {
                transport: {
                read: function (options) {
                options.success(e.data.orders);
                },
                }
                },
                });
                }
                </script>
                </div>
                </body>
                </html>








                share|improve this answer













                You cannot prevent it from collapsing because every time you change something to the data it automatically rebinds and redraw the table.



                What you can do however is to capture the rebinding, find the opened details and after the binding finish reopen them:






                <!DOCTYPE html>
                <html>
                <head>
                <meta charset="utf-8"/>
                <title>Kendo UI Snippet</title>

                <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.common.min.css"/>
                <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.rtl.min.css"/>
                <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.silver.min.css"/>
                <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.mobile.all.min.css"/>

                <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
                <script src="https://kendo.cdn.telerik.com/2018.3.1017/js/kendo.all.min.js"></script>
                </head>
                <body>

                <div id="example">
                <div id="grid"></div>

                <script>
                let data = [{id: 1, FirstName: "Nancy", LastName: "Davolio", orders: [{title: 1}, {title: 2}]}];

                $(document).ready(function () {
                let expanded = ;

                var element = $("#grid").kendoGrid({
                dataSource: data,
                toolbar: [{name: "create"}],
                height: 600,
                detailInit: detailInit,
                editable: true,
                columns: [
                {
                field: "id",
                title: "id",
                },
                {
                field: "FirstName",
                title: "First Name",
                width: "110px"
                },
                {
                field: "LastName",
                title: "Last Name",
                width: "110px"
                },
                {command: ["destroy"]},
                ],
                dataBinding: function (e) {
                expanded = $.map(this.tbody.children(":has(> .k-hierarchy-cell .k-i-collapse)"), function (row) {
                return $(row).data("uid");
                });
                },
                dataBound: function (e) {
                this.expandRow(this.tbody.children().filter(function (idx, row) {
                return $.inArray($(row).data("uid"), expanded) >= 0;
                }));
                },
                });

                });

                function detailInit(e) {
                $("<div/>").appendTo(e.detailCell).kendoGrid({
                dataSource: {
                transport: {
                read: function (options) {
                options.success(e.data.orders);
                },
                }
                },
                });
                }
                </script>
                </div>
                </body>
                </html>








                <!DOCTYPE html>
                <html>
                <head>
                <meta charset="utf-8"/>
                <title>Kendo UI Snippet</title>

                <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.common.min.css"/>
                <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.rtl.min.css"/>
                <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.silver.min.css"/>
                <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.mobile.all.min.css"/>

                <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
                <script src="https://kendo.cdn.telerik.com/2018.3.1017/js/kendo.all.min.js"></script>
                </head>
                <body>

                <div id="example">
                <div id="grid"></div>

                <script>
                let data = [{id: 1, FirstName: "Nancy", LastName: "Davolio", orders: [{title: 1}, {title: 2}]}];

                $(document).ready(function () {
                let expanded = ;

                var element = $("#grid").kendoGrid({
                dataSource: data,
                toolbar: [{name: "create"}],
                height: 600,
                detailInit: detailInit,
                editable: true,
                columns: [
                {
                field: "id",
                title: "id",
                },
                {
                field: "FirstName",
                title: "First Name",
                width: "110px"
                },
                {
                field: "LastName",
                title: "Last Name",
                width: "110px"
                },
                {command: ["destroy"]},
                ],
                dataBinding: function (e) {
                expanded = $.map(this.tbody.children(":has(> .k-hierarchy-cell .k-i-collapse)"), function (row) {
                return $(row).data("uid");
                });
                },
                dataBound: function (e) {
                this.expandRow(this.tbody.children().filter(function (idx, row) {
                return $.inArray($(row).data("uid"), expanded) >= 0;
                }));
                },
                });

                });

                function detailInit(e) {
                $("<div/>").appendTo(e.detailCell).kendoGrid({
                dataSource: {
                transport: {
                read: function (options) {
                options.success(e.data.orders);
                },
                }
                },
                });
                }
                </script>
                </div>
                </body>
                </html>





                <!DOCTYPE html>
                <html>
                <head>
                <meta charset="utf-8"/>
                <title>Kendo UI Snippet</title>

                <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.common.min.css"/>
                <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.rtl.min.css"/>
                <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.silver.min.css"/>
                <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.mobile.all.min.css"/>

                <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
                <script src="https://kendo.cdn.telerik.com/2018.3.1017/js/kendo.all.min.js"></script>
                </head>
                <body>

                <div id="example">
                <div id="grid"></div>

                <script>
                let data = [{id: 1, FirstName: "Nancy", LastName: "Davolio", orders: [{title: 1}, {title: 2}]}];

                $(document).ready(function () {
                let expanded = ;

                var element = $("#grid").kendoGrid({
                dataSource: data,
                toolbar: [{name: "create"}],
                height: 600,
                detailInit: detailInit,
                editable: true,
                columns: [
                {
                field: "id",
                title: "id",
                },
                {
                field: "FirstName",
                title: "First Name",
                width: "110px"
                },
                {
                field: "LastName",
                title: "Last Name",
                width: "110px"
                },
                {command: ["destroy"]},
                ],
                dataBinding: function (e) {
                expanded = $.map(this.tbody.children(":has(> .k-hierarchy-cell .k-i-collapse)"), function (row) {
                return $(row).data("uid");
                });
                },
                dataBound: function (e) {
                this.expandRow(this.tbody.children().filter(function (idx, row) {
                return $.inArray($(row).data("uid"), expanded) >= 0;
                }));
                },
                });

                });

                function detailInit(e) {
                $("<div/>").appendTo(e.detailCell).kendoGrid({
                dataSource: {
                transport: {
                read: function (options) {
                options.success(e.data.orders);
                },
                }
                },
                });
                }
                </script>
                </div>
                </body>
                </html>






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 25 '18 at 7:23









                MitsakosGRMitsakosGR

                342514




                342514
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51126488%2fstop-detailinit-collapse-when-adding-a-new-row-to-the-grid%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    404 Error Contact Form 7 ajax form submitting

                    How to know if a Active Directory user can login interactively

                    TypeError: fit_transform() missing 1 required positional argument: 'X'