Removed hierarchy cells reappearing after parent grid is filtered or page is changed

1 Answer 109 Views
Filter Grid
Jason
Top achievements
Rank 1
Jason asked on 13 Oct 2021, 02:27 PM
I have the following js function that is called during the dataBound event of the parent grid to remove any hierarchal cells, for readability of the users. So they don't have to expand every row to see that there is no data.
function removeHierarchyCell() {
    var data = $('#GridName').data('kendoGrid').dataSource.data();

    // Remove row expansion when no data
    $.each(data, function (i, row) {
        var hasChildren = row.get("ChildModel");

        if (hasChildren === null || hasChildren === undefined || hasChildren.length == 0) {
            $('tr[data-uid="' + row.uid + '" ] ').find(".k-hierarchy-cell a").remove();
        }
    });
}
It works as it should when the page loads, the issue comes when the parent grid is either filtered or on page change. When the grid populate  the rows they now have the expand icon in the hierarchy-cell. I've tried several things but these elements always appear after any operation on the parent grid. 

Is there some way to keep these removed from the parent grid? 

1 Answer, 1 is accepted

Sort by
0
Georgi Denchev
Telerik team
answered on 18 Oct 2021, 09:17 AM

Hi, Jason,

Thank you for the provided code snippet.

The dataBound event is triggered any time you execute a Grid operation(filtering, sorting, paging, etc.). This means that the icon should also be removed when you're applying or removing filters.

Dojo example:

https://dojo.telerik.com/@gdenchev/onuXoguc 

If the icon reappears after an operation, that means the following line is not getting reached:

$('tr[data-uid="' + row.uid + '" ] ').find(".k-hierarchy-cell a").remove();

Could you make sure that the code gets into the if condition and that the correct row is selected?

Additionally, if you could reproduce the problem in a Dojo(you can use the one from above as a starting point) and share it with me, I might be able to find what's causing the issue.

Let me know if you have any questions.

Best Regards,
Georgi Denchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Jason
Top achievements
Rank 1
commented on 19 Oct 2021, 01:37 PM

Thank you Georgi for the response! 

I will double check that line to make sure it is pulling an actual row. Also I should have mentioned this and thought I did, but I had the data for the detail gird being bound to data passed in from the parent grid model.

Could that be the cause of this behavior? 
Georgi Denchev
Telerik team
commented on 22 Oct 2021, 10:19 AM

Hi, Jason,

Generally speaking that shouldn't be a problem. The issue occurs in the parent grid, so the data in the child shouldn't have any effect on it. The more likely cause is the conditional statement, however you'll need to double-check it to be certain.

Jason
Top achievements
Rank 1
commented on 08 Nov 2021, 08:59 PM

Sorry for the lateness of this reply. But I was finally able to get back around to this. Checking the console while I was filtering and acting on the parent grid. I see that the DataBound event is not happening at all when acting on the grid. So I guess there is somewhere that might be preventing that from happening? Should that be happening on each change?
Georgi Denchev
Telerik team
commented on 11 Nov 2021, 01:30 PM

Hi, Jason,

The DataBound event should be firing after each operation - read/filter/sort/page/group. DataBound isn't preventable so there should be nothing stopping it. My only guess would be that the event is attached to a different Grid from the one you're trying to debug.

Would it be possible for you to share a small dojo where the problem is reproduced, so I can run and examine it? This might give me an idea as to what may be causing the issue.

Jason
Top achievements
Rank 1
commented on 12 Nov 2021, 02:43 PM

I tried editing that first dojo you provided, as I thought this was due to our server operations turned off.  But setting them to false on the dojo still had it working with no issue. Could this be an MVC problem? Here is the exact grid code we are using on our page. 

I'm only posting it here because I wasn't sure if there was a way to set this up in the dojo, 
@(Html.Kendo().Grid<IndexViewModel>()
          .Name("GroupGrid")
          .Columns(columns =>
          {
              columns.Bound(model => model.PlacesOfService).Filterable(f => f.Cell(cell => cell.Operator("contains").ShowOperators(false)));
              columns.Bound(model => model.GroupTypeName).Title("Group Insurance Type").Visible(@Model.IsParentGroup).Filterable(f => f.Cell(cell => cell.ShowOperators(false).Template("groupTypeFilter"))).Width(230);
              columns.Bound(model => model.GroupNumbers).ClientTemplate("<p>#:GroupNumbers#</p>").Visible(@Model.IsParentGroup).Title("Associated Groups").Filterable(f => f.Cell(cell => cell.Operator("contains").ShowOperators(false)));
              columns.Bound(model => model.PlanNumbers).ClientTemplate("<p>#:PlanNumbers#</p>").Visible(@Model.IsParentGroup).Title("Associated Plans").Filterable(f => f.Cell(cell => cell.Operator("contains").ShowOperators(false)));
              columns.Bound(model => model.Drug).Filterable(f => f.Cell(cell => cell.Operator("contains").ShowOperators(false)));
              columns.Bound(model => model.Requirements).Filterable(f => f.Cell(cell => cell.Operator("contains").ShowOperators(false)));
              columns.Bound(model => model.BeginDate).ClientTemplate("#=BeginDateToLocal#").Filterable(f => f.Cell(cell => cell.ShowOperators(false)));
              columns.Bound(model => model.EndDate).ClientTemplate("#=EndDateToLocal#").Filterable(f => f.Cell(cell => cell.ShowOperators(false)));
              columns.Bound(model => model.Active);
              columns.Bound(model => model.Id).Filterable(false).Sortable(false).Title("Actions").ClientTemplate("<a class=\"k-button k-button-icontext k-grid-edit\" href=\"" + Url.Action("Update", new { id = "#=Id#", groupId = configurationModel.GroupId, isParentGroup = configurationModel.IsParentGroup }) + "\"><span class=\"k-icon k-i-edit\"></span>Edit</a>"
                  + "<input type=\"button\" class=\"k-button\" onclick=\"openCopyWindow('#=Id#');\"value=\"Copy\" />"
                  + "<input type=\"button\" class=\"k-button\" onclick=\"groupIndexModel.toggleActive('#=Id#', '#=Active ? '" + Url.Action("Deactivate") + "' : '" + Url.Action("Activate") + "'#');\" value=\"#=Active ? 'Deactivate' : 'Activate'#\" />");
          })
        .ToolBar(toolbar =>
            toolbar.Template(@<text>
                             <div class ="row">
                                 <a id="AddNew" class="k-button k-button-icontext k-grid-add" href="@Url.Action("Create", new { groupId = configurationModel.GroupId, isParentGroup = configurationModel.IsParentGroup })"><span class="k-icon k-i-add"></span>Add new</a>
                                 <div class="input-wrapper searchBar" style="width: 30%; display: inherit;">
                                     @(Html.Kendo().TextBox().Name("groupSearch").HtmlAttributes(new { @class = "form-control border-style input-style", style = "border-radius: 6px;margin-left:75px;margin-top:2px;", @placeholder = "Search..." }))
                                     <i class="k-icon k-i-search icon-style" style="margin-left: -20px; margin-top: 12px;"></i>
                                 </div>
                             </div>
                          </text>))
          .Sortable()
          .Filterable(ftb => ftb.Mode(GridFilterMode.Row))
          .Pageable()
      .DataSource(builder => builder.Ajax().ServerOperation(false)
          .Model(dataSource => dataSource.Id(viewModel => viewModel.Id))
          .Filter(filter => filter.Add(p => p.Active).IsEqualTo(true))
          .Filter(filter => filter.Add(p => p.EndDate).IsGreaterThanOrEqualTo(DateTime.Today))
          .Sort(s => s.Add(p => p.EndDate).Descending())
          .Read(read => read.Action<GroupController>(controller => controller.GroupRead(null, configurationModel.GroupId.Value, configurationModel.IsParentGroup)))))

Eyup
Telerik team
commented on 17 Nov 2021, 08:58 AM

Hi

Thank you for providing additional details.

However, I noticed that this account doesn't have any legitimate license assigned. Can you contact your Company License Representative and ensure that he/she assigns you a valid Telerik license? Feel free to contact Telerik Sales Department for any inquiries.

Then, we can proceed with resolving the technical question.

Jason
Top achievements
Rank 1
commented on 17 Nov 2021, 02:01 PM

Hi Eyup, 

I have my company's customer ID, will that suffice? 

Eyup
Telerik team
commented on 22 Nov 2021, 08:29 AM

Hi


Tags
Filter Grid
Asked by
Jason
Top achievements
Rank 1
Answers by
Georgi Denchev
Telerik team
Share this question
or