如何在kendo网格中隐藏一行

时间:2014-06-14 19:22:52

标签: jquery kendo-ui kendo-grid kendo-asp.net-mvc

我想在编辑屏幕中使用kendo网格添加或删除作业的地址。使用删除的自定义命令,我隐藏了网格行并将其中一个隐藏属性设置为false。 当我尝试添加新地址,即新的网格行时,它显示前一个隐藏的行也带有新行,我该如何解决这个问题。 我正在使用这个剑道网格

      <div class="row" style="margin-top:10px;margin-left: 2px;margin-right: 2px;">
                    @(Html.Kendo().Grid(Model.TransportJobAddresses)
                          .Name("AddressDetail")
                          .ToolBar(tools => tools.Create().Text("Add New"))
                          .Editable(editable => editable.Mode(GridEditMode.InCell).CreateAt(GridInsertRowPosition.Bottom))
                          .Columns(columns =>
                          {
                              columns.Bound(p => p.Id).Hidden().ClientTemplate("#= Id #" +
                                                                               "<input type='hidden' name='TransportJobAddresses[#= index(data)#].Id' value='#= Id #' />"
                                  );
                              columns.Bound(p => p.TransportJobId).Hidden().ClientTemplate("#= TransportJobId #" +
                                                                                           "<input type='hidden' name='TransportJobAddresses[#= index(data)#].TransportJobId' value='#= TransportJobId #' />"
                                  );


                              columns.Bound(p => p.CompanyName).EditorTemplateName("JobAddressGridEditor").ClientTemplate("#= CompanyName #" +
                                                                                                                          "<input type='hidden' name='TransportJobAddresses[#= index(data)#].CompanyName' value='#= CompanyName #' />"

                                  ).Width(100);
                              //.EditorTemplateName("CustomerJobHistoryAuto");

                              columns.Bound(p => p.Address1).ClientTemplate("#= Address1 #" +
                                                                            "<input type='hidden' name='TransportJobAddresses[#= index(data)#].Address1' value='#= Address1 #' />"
                                  ).Width(80);

                              columns.Bound(p => p.Address2).ClientTemplate("#= Address2 #" +
                                                                            "<input type='hidden' name='TransportJobAddresses[#= index(data)#].Address2' value='#= Address2 #' />"
                                  ).Width(80);

                              columns.Bound(p => p.City).ClientTemplate("#= City #" +
                                                                        "<input type='hidden' name='TransportJobAddresses[#= index(data)#].City' value='#= City #' />"
                                  ).Width(80);
                              columns.Bound(p => p.County).ClientTemplate("#= County #" +
                                                                          "<input type='hidden' name='TransportJobAddresses[#= index(data)#].County' value='#= County #' />"
                                  ).Width(80);
                              columns.Bound(p => p.PostCode).EditorTemplateName("PostCodeGridEditor").ClientTemplate("#= PostCode #" +
                                                                            "<input type='hidden' name='TransportJobAddresses[#= index(data)#].PostCode' value='#= PostCode #' />"
                                  ).Width(80);
                              columns.Bound(p => p.AddressSequenceId).Hidden().ClientTemplate("#= AddressSequenceId #" +
                                                                            "<input type='hidden' name='TransportJobAddresses[#= index(data)#].AddressSequenceId' value='#= AddressSequenceId #' />"
                                  ).Width(80);
                              columns.Bound(p => p.IsActive).Hidden().ClientTemplate("#= IsActive #" +
                                                                            "<input type='hidden' name='TransportJobAddresses[#= index(data)#].IsActive' value='#= IsActive #' />"
                                  ).Width(80);
                              columns.Bound(p => p.GlobalTransportJobAddressTypeId).Hidden().ClientTemplate("#= GlobalTransportJobAddressTypeId #" +
                                                                            "<input type='hidden' name='TransportJobAddresses[#= index(data)#].GlobalTransportJobAddressTypeId' value='#= GlobalTransportJobAddressTypeId #' />"
                                  ).Width(80);

                              columns.Command(command => command.Destroy()).Title("Delete").Width(80).Hidden();
                              columns.Command(cmd => cmd.Custom("Del").Click("DelAddrAction")).Width(80);
                              //columns.Command(command => command.Custom("Show").Click("editItem")).Title("Show").Width(80);

                          })

                          .DataSource(dataSource =>
                              dataSource.Ajax()
                                  .Model(model => model.Id(p => p.Id))
                                  .ServerOperation(false)

                          ).Resizable(c => c.Columns(true))
                        .Events(e => e.Remove("removedataitem"))
                    )
                </div>

enter image description here

       Code under del button 

      function DelAddrAction(e) {
            var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
            var hiderow=  $(e.currentTarget).closest("tr")
            dataItem.IsActive = false;
            //setting hidden input bool value in client template 
            var setflag = hiderow.find('input[name*="].IsActive"]').val(false);
           hiderow.hide();
       }

0 个答案:

没有答案