当尝试使用ASP从Kendo UI网格中的子网格重定向时出错。NET MVC

时间:2022-09-12 09:13:56
@(Html.Kendo().Grid<ClaimTravelCashSelectByApproverId_Result>()
        .Name("grid")
        .Columns(columns =>
        {
            columns.Bound(e => e.chkbox)
                .HeaderTemplate("<input type='checkbox' id='chkAllClaim'/>")
                .ClientTemplate("<input type='checkbox' class='clsClaim'/>")
                .HtmlAttributes(new { style = "text-align: center" })
                .Filterable(false)
                .Width(50);
            columns.Bound(e => e.Name)
                .Filterable(filterable => filterable.UI("name"))
                .Width(150)
                .Title("Claim");
            columns.Bound(e => e.Description)
                .Filterable(false)
                    .Width(150);
            columns.Bound(e => e.Amount)
                .Filterable(false)
                    .Width(100);
            columns.Bound(e => e.Status)
                    .Width(100);
            columns.Bound(e => e.FullName)
                    .Width(150);
            columns.Bound(e => e.CreatedDate).ClientTemplate("#= kendo.toString(kendo.parseDate(CreatedDate,'dd/MM/yyyy'), '" + ProjectSession.DateFormat + "') #")
                    .Width(100);
            columns.Template(@<text></text>).ClientTemplate(
        @Html.ViewLink("View Comment", "javascript:", null, null, new { datahref = Url.Action("_ViewClaimComment", "Home", new { Data = "#=ClaimId#" }), @class = "clsView" }).ToHtmlString())
        .Width(50);

        })
        .Sortable()
        .Pageable()
        .Scrollable()
        .ClientDetailTemplateId("template")
        .HtmlAttributes(new { style = "height:1000px;" })
        .Filterable(filterable => filterable
        .Extra(false)
         .Operators(operators => operators
            .ForString(str => str.Clear()
                .StartsWith("Starts with")
                .IsEqualTo("Is equal to")
                .IsNotEqualTo("Is not equal to")
            ))
        )
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(6)
                    .Read(read => read.Action("claimApproverList", "Approver"))
        )
        .Events(events => events.DataBound("dataBound")))

<script id="template" type="text/kendo-tmpl">@(Html.Kendo().Grid<ClaimSelectByApproverIdByClaimId_Result>()
            .Name("grid_#=ClaimId#")
            .Columns(columns =>
            {
                columns.Bound(o => o.ClaimId).Width(110);
                columns.Bound(o => o.ClaimTypeId).Width(110);
                columns.Bound(o => o.ClaimTypeName).Width(110);
                columns.Bound(o => o.NoOfItems).Width(110);
                columns.Template(@<text></text>).ClientTemplate(
                    @Html.ViewLink("View", "RedirectByClaimTypeName", "Approver", new { Data = "#=ClaimId#" , TypId = "#=ClaimTypeId#" }).ToHtmlString())
                    .Width(50);
            })
            .DataSource(dataSource => dataSource
                .Ajax()
                //.PageSize(10)
                .Read(read => read.Action("GetClaimInnerGridByClaimId", "Approver", new { ClaimId = "#=ClaimId#" }))
            )
            //.Pageable()
            //.Sortable()
            .ToClientTemplate()
)</script>

/* View comment fro claim*/
$(".clsView").click(function (e) {
    e.preventDefault();
    e.stopPropagation();
    alert($(this).attr("datahref"));
    $("#divCommentsdialog").load($(this).attr("datahref")).dialog({
        modal: true,
        height: 450,
        width: 600,
        draggable: false,
        resizable: false,
        dialogClass: 'no-close success-dialog',
        title: '@objFieldNameList["Claim"]' + " " + '@objFieldNameList["Comment"]',
        close: function (event, ui) {
            $(this).dialog('destroy');
            $("#divCommentsdialog").empty();
        }
    });
});




$("#chkAllClaim").click(function () {
    $('.clsClaim').prop('checked', $(this).is(':checked'));
});



/* If all checkbox is checked than top checkbox will be checked.*/
$('.clsClaim').click(function () {
    if ($('.clsClaim:not(:checked)').length > 0) {
        $("#chkAllClaim").prop('checked', false);
    }
    else {
        $("#chkAllClaim").prop('checked', true);
    }
});

Now my issues are:

现在我的问题是:

  1. when I checked 'chkAllClaim', Kendo grid seems like to be postback and checkbox unchecked (don't know what exactly happens after my js function)

    当我选中“chkAllClaim”时,Kendo网格看起来像是回发和复选框未选中(不知道js函数之后会发生什么)

  2. when I am clicking on class 'clsView', it doesn't go to js function (when from browser I am inserting that function then working)

    当我点击class 'clsView'时,它不会转到js函数(当我在浏览器中插入这个函数然后工作)

  3. In my first grid , I got "#=ClaimId#" , for "View Comment" , In second grid(child grid) I also got "#=ClaimId#" , but when I try to get "#=ClaimTypeId#" , I GOT ERROR : ReferenceError: ClaimTypeId is not defined (where the hell problem is ?)

    在我的第一个网格中,我得到了“#=ClaimId#”,用于“View Comment”,在第二个网格(子网格)中我也得到了“#=ClaimId#”,但是当我尝试获得“#=ClaimTypeId#”时,我得到了错误:ReferenceError: ClaimTypeId没有定义(该死的问题在哪里?)

I have take reference from here : http://demos.telerik.com/aspnet-mvc/grid/hierarchy

我从这里引用了http://demos.telerik.com/aspnet-mvc/grid/hierarchy

1 个解决方案

#1


1  

just use \\ for the inner grid binding before #

使用\在#之前的内部网格绑定

  @(Html.Kendo().Grid<Uhrs.Domain.Entities.EntityPermission>()
          .Name("grid_#=FundUserRoleId#") // make sure the Name is unuque
          .Columns(columns =>
          {
              columns.Bound(p => p.MenuID).Visible(false);
              columns.Bound(p => p.MenuName).ClientTemplate("<strong>\\#:MenuName\\#</strong>");
              columns.Bound(p => p.MenuStatus).ClientTemplate("<input type='checkbox' \\#: MenuStatus? checked='checked': checked='' \\# class='chkbx' onclick='checkBoxClick(this,#=FundUserRoleId#)' />");


          })
          .ToolBar(toolbar => toolbar.Save())
          .Editable(editable => editable.Mode(GridEditMode.InCell))
          .HtmlAttributes(new { style = "width:610px;" })
          .DataSource(dataSource =>
              dataSource
              .Ajax()
              .Batch(true)
              .ServerOperation(false)
              .PageSize(20)
              .Model(model =>
                    {
                        model.Id(p => p.MenuID);
                        model.Field(p => p.MenuName).Editable(false);

                    })
              .Events(events => events.Error("error_handler").RequestEnd("onRequestEndChildGrid"))
              .Read(read => read.Action("ReadUserPermissions", "Admin", new { linkFundUserId = "#=FundUserRoleId#" }))
              .Create(create => create.Action("CreateUserPermissions", "Admin", new { linkFundUserId = "#=FundUserRoleId#" }))
              .Update(update => update.Action("UpdateUserPermissions", "Admin", new { linkFundUserId = "#=FundUserRoleId#", roleID = "#=Role.RoleId#" }))
          )
          .Pageable()
          .ToClientTemplate()
    )

#1


1  

just use \\ for the inner grid binding before #

使用\在#之前的内部网格绑定

  @(Html.Kendo().Grid<Uhrs.Domain.Entities.EntityPermission>()
          .Name("grid_#=FundUserRoleId#") // make sure the Name is unuque
          .Columns(columns =>
          {
              columns.Bound(p => p.MenuID).Visible(false);
              columns.Bound(p => p.MenuName).ClientTemplate("<strong>\\#:MenuName\\#</strong>");
              columns.Bound(p => p.MenuStatus).ClientTemplate("<input type='checkbox' \\#: MenuStatus? checked='checked': checked='' \\# class='chkbx' onclick='checkBoxClick(this,#=FundUserRoleId#)' />");


          })
          .ToolBar(toolbar => toolbar.Save())
          .Editable(editable => editable.Mode(GridEditMode.InCell))
          .HtmlAttributes(new { style = "width:610px;" })
          .DataSource(dataSource =>
              dataSource
              .Ajax()
              .Batch(true)
              .ServerOperation(false)
              .PageSize(20)
              .Model(model =>
                    {
                        model.Id(p => p.MenuID);
                        model.Field(p => p.MenuName).Editable(false);

                    })
              .Events(events => events.Error("error_handler").RequestEnd("onRequestEndChildGrid"))
              .Read(read => read.Action("ReadUserPermissions", "Admin", new { linkFundUserId = "#=FundUserRoleId#" }))
              .Create(create => create.Action("CreateUserPermissions", "Admin", new { linkFundUserId = "#=FundUserRoleId#" }))
              .Update(update => update.Action("UpdateUserPermissions", "Admin", new { linkFundUserId = "#=FundUserRoleId#", roleID = "#=Role.RoleId#" }))
          )
          .Pageable()
          .ToClientTemplate()
    )