Working with treegrid is not easy.

Working with treegrid is not easy.


I am working on registering/editing/deleting a menu list with treegrid, and I would like to ask you a few questions.


1. If you set mode = "Batch", newposition = "Below", select one row and add it, the row is added, but the cell is not in Edit state.

(When working with a regular Grid, when you add, the mouse cursor is waiting for input within the cell.)


2. If you double-click a cell to edit it in question 1 above, an Error appears.

2024-05-31 08:03:12.111 +09:00 [WRN] Unhandled exception rendering component: Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
   at Syncfusion.Blazor.TreeGrid.Internal.GridRenderer`1.TreeRowSelectedHandler[T](RowSelectEventArgs`1 gridArgs)
   at Syncfusion.Blazor.TreeGrid.Internal.GridRenderer`1.RowSelectedHandler(RowSelectEventArgs`1 gridArgs)
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at Syncfusion.Blazor.Grids.Internal.Selection`1.SelectByRow(Row`1 rowToSelect, MouseAndKeyArgs evt, Boolean isSelectionMethodInvoked, Boolean isScrollIntoView, Int32 focusColumnIndex)
   at Syncfusion.Blazor.Grids.Internal.Selection`1.ValidateRowSelectionClick(Row`1 row, MouseAndKeyArgs e)
   at Syncfusion.Blazor.Grids.Internal.Selection`1.RowSelectionClickHandler(MouseAndKeyArgs e, ValueTuple`3 target)
   at Syncfusion.Blazor.Grids.Internal.Selection`1.ClickHandler(MouseEventArgs e, ValueTuple`3 target)
   at Syncfusion.Blazor.Grids.Internal.GridCellBase`1.CellClickHandler(MouseEventArgs e, Boolean IsCheckBox)
   at Syncfusion.Blazor.TreeGrid.Internal.TemplateCell`2.<BuildRenderTree>b__0_0(MouseEventArgs e)
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)


3. When the value of a specific cell changes, I want to change the value of other cells in the row.


4. I want to edit with Single Click.


5. When changing the EditTemple to CheckBox, can you confirm that the Grid has also changed if the CheckBox state is changed?


6. In batch mode, is there a way to check only the modified items when saving?


7. Is it necessary to use EnableVirtualization="true"?

Looking at most test sources, I saw that there was no EnableVirtualization="true" property, and the part that fetched data was executed in OnInitializedAsync(). However, I first search in OnAfterRenderAsync() and, if necessary, search with the search button, but without EnableVirtualization="true", the search does not work.


That is all.


(The source below is a test source with settings similar to the source I am working on.)


------ source ------


@page "/"
@using Syncfusion.Blazor.TreeGrid
@using Syncfusion.Blazor.Grids

        <SfTreeGrid @ref="obj_Grid_Menu" DataSource="@tree" Height="100%" Width="auto" IdMapping="TaskID" ParentIdMapping="ParentID" TreeColumnIndex="1" AllowPaging="true"
                    AllowSorting="false" AllowTextWrap="true"
                    Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })"
                    EnableVirtualization="true">
            <TreeGridPageSettings PageSize="100"></TreeGridPageSettings>
            <TreeGridEvents RowSelected="RowSelectHandler" OnActionComplete="Grid_Menu_Complete" TValue="Order"></TreeGridEvents>
            <TreeGridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="Syncfusion.Blazor.TreeGrid.EditMode.Batch"
                                    NewRowPosition="Syncfusion.Blazor.TreeGrid.RowPosition.Below"></TreeGridEditSettings>
            <TreeGridColumns>
                <TreeGridColumn Field=@nameof(Order.TaskID) HeaderText="Id" Width="80" ValidationRules="@(new Syncfusion.Blazor.Grids.ValidationRules() { Required = true, Number = true })" IsPrimaryKey="true" AllowEditing="false"></TreeGridColumn>
                <TreeGridColumn Field=@nameof(Order.TaskName) HeaderText="page" Width="150" ValidationRules="@(new Syncfusion.Blazor.Grids.ValidationRules() { Required = true })" >
                </TreeGridColumn>
                <TreeGridColumn Field=@nameof(Order.Use_yn)  HeaderText="use"  Width="90">
                    <Template>
                        <SfCheckBox @ref="chk_useyn" @bind-Checked=@((context as Order).Use_yn)></SfCheckBox>
                    </Template>
                </TreeGridColumn>
            </TreeGridColumns>
        </SfTreeGrid>

@code {
    SfTreeGrid<Order>? obj_Grid_Menu;

    public static List<Order> tree = new List<Order>();

    SfCheckBox<bool?> chk_useyn;

    public double PreviousSelectedIndex = -1;

    public bool b_PageNameEnableCheck = true;

    public int tempId = 1000; // add 버튼 누르면 ++

    protected override async Task OnInitializedAsync()
    {
       
    }
    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            await RetrieveClick();
        }
    }


    private async Task RetrieveClick()
    {
        tree = GetOrder();
        StateHasChanged();
    }

    private async Task AddClick()
    {
        await obj_Grid_Menu.AddRecordAsync(newDataCall(), (int)PreviousSelectedIndex, Syncfusion.Blazor.TreeGrid.RowPosition.Below);
    }

    private async Task SaveClick()
    {
        await obj_Grid_Menu.EndEditAsync();

        //???????
        // foreach (var modifiedItem in ds_MenuTree.Where(item => item.HasChanges))
        // {
        // }
    }
   
    public async Task Grid_Menu_Begin(Syncfusion.Blazor.Grids.ActionEventArgs<Order> args)
    {
       
    }

    public async void Grid_Menu_Complete(Syncfusion.Blazor.Grids.ActionEventArgs<Order> args)
    {
       
    }

    public async Task CellSelectHandler(CellSelectEventArgs<Order> args)
    {
        //get selected cell index
        var CellIndexes = await obj_Grid_Menu.GetSelectedRowCellIndexesAsync();

        // // Get the selected cell index
        // var rowIndex = args.RowIndex;
        // var columnIndex = args.CellIndex;

        //get the row and cell index
        var CurrentEditRowIndex = CellIndexes[0].Item1;
        var CurrentEditCellIndex = (int)CellIndexes[0].Item2;

        //get the available fields
        var fields = await obj_Grid_Menu.GetColumnsAsync();
        // edit the selected cell using the cell index and column name
        await obj_Grid_Menu.EditCellAsync(CurrentEditRowIndex, fields[CurrentEditCellIndex].Field);
    }

   
    public void RowSelectHandler(RowSelectEventArgs<Order> args)
    {
        PreviousSelectedIndex = args.RowIndex; // saving the selected row index
    }

    public Order newDataCall()
    {
        ++tempId;
        Order newdata = new Order()
            {
                TaskID = tempId,
                TaskName = "Parent Task !!!!",
                Use_yn = true
            };

        return newdata;
    }

    public class Order
    {
        public int? TaskID { get; set; }
        public string TaskName { get; set; }
        public bool? Use_yn { get; set; }
        public int? ParentID { get; set; }
    }

    public static List<Order> GetOrder()
        {
            tree.Clear();
            int root = -1;
            int TaskNameID = 0;
            int ChildCount = -1;
            for (var t = 1; t <= 2; t++)
            {
                Random gen = new Random();
                Random ran = new Random();
                root++; TaskNameID++;
                int rootItem = root + 1;
                tree.Add(new Order() { TaskID = rootItem, TaskName = "Parent Task " + TaskNameID.ToString(), ParentID = null, Use_yn = true });
                int parent = tree.Count;
                for (var c = 0; c < 2; c++)
                {
                    root++; ChildCount++;
                    int iD = root + 1;
                    tree.Add(new Order() { TaskID = iD, TaskName = "Child Task " + (ChildCount + 1).ToString(), ParentID = rootItem, Use_yn = true});
                }
            }
            return tree;
        }
}




7 Replies 1 reply marked as answer

AG Ajithkumar Gopalakrishnan Syncfusion Team June 6, 2024 04:23 AM UTC

Hi Junghwi,

Query 1, 2:  if you set mode = "Batch", newposition = "Below", select one row and add it, the row is added, but the cell is not in Edit state. (When working with a regular Grid, when you add, the mouse cursor is waiting for input within the cell.)


We have logged the problem “Adding not working when using Batch mode" as bug. We are working on a fix for this issue and plan to include it in our upcoming patch release, which is currently scheduled for Jun, 26 2024.

You can track the progress of the resolution by visiting the feedback link provided below:


Feedback link:
   https://www.syncfusion.com/feedback/58426/adding-not-working-when-using-batch-mode

Disclaimer: Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization.

Query 2:  I want to edit with Single Click.


To achieve your requirement, we suggest using the cellSelected event in TreeGrid. This event triggers after a cell is selected, which in turn calls the EditCell method. We have attached the code snippet and a modified sample for reference.

Ug link: https://blazor.syncfusion.com/documentation/treegrid/how-to/single-click-editing-with-batch-mode?cs-save-lang=1&cs-lang=razor

<SfTreeGrid ..

           >

    <TreeGridPageSettings PageSize="100"></TreeGridPageSettings>

    <TreeGridSelectionSettings Mode="Syncfusion.Blazor.Grids.SelectionMode.Both"></TreeGridSelectionSettings>

    <TreeGridEvents CellSelected="CellSelectHandler" OnActionComplete="Grid_Menu_Complete" TValue="Order"></TreeGridEvents>

    <TreeGridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="Syncfusion.Blazor.TreeGrid.EditMode.Batch"

                          NewRowPosition="Syncfusion.Blazor.TreeGrid.RowPosition.Below"></TreeGridEditSettings>

  … 

</SfTreeGrid>

public async Task CellSelectHandler(CellSelectEventArgs<Order> args)

{

    //get selected cell index

    var CellIndexes = await obj_Grid_Menu.GetSelectedRowCellIndexesAsync();

 

    // // Get the selected cell index

    // var rowIndex = args.RowIndex;

    // var columnIndex = args.CellIndex;

 

    //get the row and cell index

    var CurrentEditRowIndex = CellIndexes[0].Item1;

    var CurrentEditCellIndex = (int)CellIndexes[0].Item2;

 

    //get the available fields

    var fields = await obj_Grid_Menu.GetColumnsAsync();

    // edit the selected cell using the cell index and column name

    await obj_Grid_Menu.EditCellAsync(CurrentEditRowIndex, fields[CurrentEditCellIndex].Field);

}


Query 3: When changing the EditTemple to CheckBox, can you confirm that the Grid has also changed if the CheckBox state is changed?


We have checked the EditTemplate using the checkbox column, and it is working fine.

Query 4: In batch mode, is there a way to check only the modified items when saving?


To achieve your requirement, we suggest to use the OnBatchSave event in TreeGrid. This event triggers after a batch save click and returns the changed records. We have attached the code snippet and modified sample for reference.

<SfTreeGrid

           >

   

    <TreeGridEvents OnBatchSave="BatchSaveHandler" TValue="Order"></TreeGridEvents>

  …      

</SfTreeGrid>

public void BatchSaveHandler(BeforeBatchSaveArgs<Order> args)

{

    // Here you can customize your code

}


Query 5: Is it necessary to use EnableVirtualization="true"?

We have checked the shared sample, and it is not necessary to set EnableVirtualization to true because the sample renders a manageable amount of records. Also, we verified that searching works fine on our end. If you are still facing issues, please share the sample with replication steps, and we will provide further details.

Query 6: When the value of a specific cell changes, I want to change the value of other cells in the row.

To achieve your requirement, we suggest using the OnCellSave event in TreeGrid. This event triggers after a cell is saved, allowing other columns to be modified based on specific conditions. We have attached a code snippet and a modified sample for reference.

<SfTreeGrid

            >

   

    <TreeGridEvents OnCellSave="CellSaveHandler"  TValue="Order"></TreeGridEvents>

…    

</SfTreeGrid>

public void CellSaveHandler(CellSaveArgs<Order> args)

{

    // Here you can customize your code

    if(args.Data != null)

    {

        args.Data.Use_yn = false;

    }

}


Sample link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Index459940017.zip

If you have any further concerns or questions, please don't hesitate to reach out to us. We are here to assist you.


Regards,

Ajithkumar G



JU junghwi July 2, 2024 04:11 PM UTC

hi.

How is the fixing of the bug registered as feedback above progressing?

Also, the version I have is version 24.2.3. If it is modified, will that version also be reflected? (There are no plans to upgrade to a higher version within this year)



PS Pon Selva Jeganathan Syncfusion Team July 5, 2024 01:39 PM UTC

Hi Junghwi,


Sorry for the inconvenience.


Unfortunately, we were unable to include the fix for the issue ” Exception thrown when we try to click on the edit form in batch mode as promised due to some internal complexities. We are working on this issue with high priority.  We will include the fix in our upcoming weekly patch release, which is expected to be rolled out on July 16th, 2024.  Until then we value your patience.


We will provide the bug fix in the latest version only. We will try to provide a custom patch with the mentioned version. In case of any issues with this version, we will provide the latest version fix.


Regards,

Pon selva




PS Pon Selva Jeganathan Syncfusion Team July 16, 2024 01:29 PM UTC

Hi Junghwi,


Thanks for your patience.


The reported issue occurred because the cell value not updated because of fiedlname not matches with ErrorResult.  We are glad to announce that fix for the issue

Exception thrown when we try to click on the edit form in batch modehas been rolled out in our weekly Nuget release.  So, upgrade to our latest version(26.1.42) of Syncfusion Nuget to resolve the reported issue.  Find the Nuget for latest fixes and features from below.


Nuget : https://www.nuget.org/packages/Syncfusion.Blazor.TreeGrid


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/BlazorApp_(3)-1156422981


Release note: https://blazor.syncfusion.com/documentation/release-notes/26.1.42?type=all#tree-grid


Kindly get back to us for further assistance.





JU junghwi replied to Pon Selva Jeganathan July 16, 2024 02:11 PM UTC

I'm glad it's been fixed.

However, the license we have is version 24.2.3, and we are not planning to renew it until this year. Is there no way to apply the bug fixes?



SM Shek Mohammed Asiq Abdul Jabbar Syncfusion Team July 22, 2024 02:12 PM UTC

Hi Junghwi,


As per your request, we are generating the custom patch on your reported version (24.2.3). We will share the custom patch on or before 24 July 2024. Until then we appreciate your patience.


Regards,

Shek



SM Shek Mohammed Asiq Abdul Jabbar Syncfusion Team July 24, 2024 02:51 PM UTC

Hi Junghwi,


We have prepared the custom patch on the mentioned version (24.2.3). Please refer to the following custom NuGet.

https://www.syncfusion.com/downloads/support/directtrac/general/ze/NuGet-1182346365


Kindly use the above NuGet to overcome your issue.


Regards,

Shek


Marked as answer
Loader.
Up arrow icon