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

Problem - select all checkbox selects disabled row

2 Answers 1223 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Simona
Top achievements
Rank 1
Simona asked on 10 Dec 2019, 04:00 PM

Hello,

 

I have a grid and I'm disabled  the row that has the approved  FALSE, but when I check Select All it checks also the disabled row.

 

(Html.Kendo().Grid<WhereAbouts.ViewModels.LoginUserViewModel>
                                    ().
                                    Name("Team")
                                    .Columns
                                    (columns =>
                                    {
                                        columns.Select().Width(50);
                                        //columns.Bound(c=>c.InsertDate);
                                        columns.Bound(c => c.BadgeNumber).ClientFooterTemplate("<button onclick='getCheckedRows()'  class='k-button k-button-icontext k-grid'>Approve</button>");
                                        columns.Bound(c => c.FullName);
                                        columns.Bound(c => c.NumberOfHours).Filterable(false);
                                        columns.Bound(c => c.Approved).Filterable(false).Title("Status");
                                        columns.Bound(c => c.ApprovalManagerId).Hidden(true);
                                        columns.Bound(c => c.Id).Title(" ").ClientTemplate("<a role='button' class='k-button k-button-icontext k-grid' href='" + Url.Action("Overtime", "Overtimes") + "?=#=" + @ViewBag.PeriodIdForGrid + "#&loginId=#=Id" + "#" + "&DropDownPeriodWeek=#=" + @ViewBag.PeriodWeekIdForGrid + "#" + "'>View</a>").Filterable(false);
                                        columns.Bound(c => c.Id).Title(" ").ClientTemplate(
                                        "# if (NumberOfHours > 0) { #" +
                                        "<a role='button' class='k-button k-button-icontext k-grid' href='" + Url.Action("Export_Teams_Overtime", "Overtimes") + "/#=Id#?DropDownPeriod=#=" + @ViewBag.PeriodIdForGrid + "#" + "'>Export</a>" +
                                        "# } else { #" +
                                        "<a role='button' disabled class='k-button k-button-icontext k-grid' href='" + Url.Action("Export_Teams_Overtime", "Overtimes") + "/#=Id#?DropDownPeriod=#=" + @ViewBag.PeriodIdForGrid + "#" + "'>Export</a>" +
                                        "# } #").Filterable(false);
                                        columns.Bound(c => c.Id).Title(" ").ClientTemplate("# if (Approved == true ) { #" +
                                        "<a role='button' class='k-button k-button-icontext k-grid' href='" + Url.Action("ApproveTeamOvertime", "Overtimes") + "/#=" + @ViewBag.PeriodIdForGrid + "#?loginId=#=Id" + "#" + "' disabled>Approve</a>" +
                                        "# } else if(ApprovalManagerId ==" + @ViewBag.LoginUserId + "){ #" +
                                        "<a role='button' class='k-button k-button-icontext k-grid' href='" + Url.Action("ApproveTeamOvertime", "Overtimes") + "/#=" + @ViewBag.PeriodIdForGrid + "#?loginId=#=Id" + "#" + "'disabled>Approve</a>" +
                                        "# } else{ #" +
                                        "<a role='button' class='k-button k-button-icontext k-grid' href='" + Url.Action("ApproveTeamOvertime", "Overtimes") + "/#=" + @ViewBag.PeriodIdForGrid + "#?loginId=#=Id" + "#" + "'>Approve</a>" +
                                        "# } #").Filterable(false);
                                    })

                                        .HtmlAttributes(new { style = "height: auto;width:auto" })
                                        .Scrollable()
                                        .Pageable(pageable =>
                                        {
                                            pageable.Refresh(true);
                                            pageable.PageSizes(true);
                                        })
                                        .HtmlAttributes(new { style = "height: auto;width: auto" })
                                        .Scrollable()
                                        .Events(e=>e.DataBound("test"))
                                        .DataSource(dataSource => dataSource
                                        .Ajax()
                                        .Model(model =>
                                        {
                                            model.Id(c => c.Id);
                                        })
                                        .Read(read => read.Action("Read_Team_Test", "OverTimes", new { periodId = @ViewBag.PeriodIdForGrid, periodWeekId = @ViewBag.PeriodWeekIdForGrid, tab = 1 }))
                                        )

 

This is the JS

 

    function test(e) {
        var grid = this;
        this.tbody.find('tr').each(function () {
            var dataItem = grid.dataItem(this);
            if (dataItem.Approved === false) {
                $(this).addClass('disable-cells');

            }
        })
    }

 

I would like to select all rows except the disabled one.

 

Is it posible?

Also, might help if I can disable the Select All from header.

 

Thank you!

2 Answers, 1 is accepted

Sort by
0
Alex Hajigeorgieva
Telerik team
answered on 12 Dec 2019, 12:35 PM

Hello, Simona,

Thank you for the provided code snippet.

I created a runnable example to check with you if this is the desired behaviour:

https://dojo.telerik.com/@bubblemaster/oZUCobiT/2

If this is the case, you can achieve the same behaviour by adding a change event handler to the Kendo UI Grid for ASP.NET Core and deselecting the row and unchecking the disabled rows checkbox, similar to this:

// this is a Grid event triggered when selection occurs
.Events(e=>e.Change("onChange"))

<script>
  function onChange(arg) {
      $(".disable-cells").removeClass("k-state-selected");
      $(".disable-cells").find(".k-checkbox").prop("checked", false);
  }
</script>

Give this a try and let me know in case you have further questions.

Kind Regards,
Alex Hajigeorgieva
Progress Telerik

Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
0
Simona
Top achievements
Rank 1
answered on 16 Dec 2019, 02:07 PM

Hello,

 

Thank you verry much,this is what I tried to achive, in the mean time I've found a solution, but yours is even better.

Tags
Grid
Asked by
Simona
Top achievements
Rank 1
Answers by
Alex Hajigeorgieva
Telerik team
Simona
Top achievements
Rank 1
Share this question
or