Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2732
DataGrid TemplateColumn context not updating on filtering, sorting
posted

Hello,

I am currently using a datagrid to display some data. I have a TemplateColumn that displays 2 buttons with actions, when clicked they execute a method with the current row's context. These buttons should only be shown if the Status property of the RowItem is "Waiting".

My TemplateColumn looks like this:

<TemplateColumn HeaderText="Actions" Field="" IsFilteringEnabled="false" IsResizingEnabled="false" IsColumnOptionsEnabled="false">
            <Template>
                @if (((Mail)context.RowItem).Status == "Waiting")
                {
                    <div style="width:100%; height:100%">
                        <button type="button" class="btn btn-link" @onclick="() => AttemptSendMail((Mail)context.RowItem)">Send</button>
                        <button type="button" class="btn btn-link" @onclick="() => AttemptRejectMail((Mail)context.RowItem)">Reject</button>
                    </div>
                }
            </Template>
        </TemplateColumn>

I have noticed that these buttons are not displayed in the correct row (should only be displayed if Status =="Waiting"), or use the correct row-context when I perform certain actions.

1. I add or remove a filter to the datagrid by code, using it's FilterExpressions. Or by manually selecting a filter using the datagrid's columnoptions in the UI.

2. When I sort a column in the grid.

Even though the status of the displayed items is not "Waiting", the buttons remain visible in their original position when filtering or sorting. Some new buttons do appear in newly displayed rows where the Status is "Waiting". When clicking the displayed buttons, the rowItem.Context remains the same as the original row that was there. Making the actions use the wrong data.  

Also, is it possible to disable sorting specifically on a column?

Parents
No Data
Reply
  • 34430
    Offline posted

    Hello Michael,

    I have been investigating into the behavior you are seeing, and I have reproduced it. It appears that at the moment, the TemplateColumn is not raising notifications of a change if it does not have the Field property set to the property it is dependent on. As such, in the case of your code snippet, I would recommend setting the Field property of your TemplateColumn to “Status” to work around this behavior.

    Regarding disabling sorting on a particular column, there does not appear to be anything to allow this at the moment, but it should certainly be implemented in a future release. For the moment, you can handle the SortDescriptionsChanged event on the grid and remove the sort description as it is added. As an example event handler, see the below code, which will prevent sorting on a column with its Field set to “ID”:

        public void OnSortDescriptionsChanged(GridSortDescriptionsChangedEventArgs args)
        {
            ColumnSortDescription desc = args.SortDescriptions.Where(d => d.Field == "ID").FirstOrDefault();
    
            if(desc != null)
            {            
                args.SortDescriptions.Remove(desc);
            }
        }

    The sorting and filtering issue is unexpected, and as such, I have asked our engineering staff to examine it further. I have logged this behavior in our internal tracking systems with a development ID of 271572. I have also created a private support case for you in this case with an ID of CAS-209753-H7B7M7 that I will be linking to this behavior. You can access this support case after logging into your account here: https://www.infragistics.com/my-account/support-activity.

    Please let me know if you have any other questions or concerns on this matter.

Children
No Data