We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Set RowRenderingMode from code.

I have a SfGrid which works fine. However, I'd like to set the RowRenderingMode from code something like:

RowRenderingMode="@direction"

protected RowDirection direction;

protected override void OnAfterRender(bool firstRender)

{

    if(condition)

        direction = RowDirection.Vertical;

    else

        direction = RowDirection.Horizontal

}


I also found that using EnableAdaptiveUI did not work as the grid overflow across the footer and I was unable to find a way to keep the footer below the grid.


9 Replies

GP Guillermo Perez February 20, 2022 07:11 AM UTC

I'M NOT FROM SUPPORT, but here's my opinion:

1) Create a reference to the object like this:

<SfGrid TValue="myTval" @ref="MyGrid" etc...>

2) Create a variable (property) to hold the reference:

private SfGrid<myTval> MyGrid { get; set; }

3) Set the value from any method you may like, on button click or anything:

<button class="btn btn-primary" @onclick="ChangeDirection">Click me!</button>

@code{

private void ChangeDirection(){

MyGrid.RowRenderingMode = RowDirection.Horizontal;

}

}

Hope that helps you.



MA Mark replied to Guillermo Perez February 20, 2022 09:15 PM UTC

Thank you for your rapid response - much appreciated. Sadly, this does not work as it generates a BL0005 warning (https://docs.microsoft.com/en-us/aspnet/core/diagnostics/bl0005?view=aspnetcore-6.0 ) and, even if the warning is ignored, the mode does not change. I'll keep tearing some hair out! 



RN Rahul Narayanasamy Syncfusion Team February 21, 2022 02:48 PM UTC

Hi Mark, 

Greetings from Syncfusion. 

You want to change the RowRenderingMode dynamically from code. Here, we have prepared a simple sample based on your requirement. We have rendered Custom Grid component and passed the RowRenderingMode to change the rendering mode. Find the below code snippets and sample for your reference. 

[Index.razor] 
 
<button class="btn btn-primary" @onclick="ChangeVerticalDirection">ChangeVerticalDirection!</button> 
<button class="btn btn-primary" @onclick="ChangeHorizontalDirection">ChangeHorizontalDirection!</button> 
 
<div class="required-container"> 
    @if (Mode == "Vertical") 
    { 
        <div class="content-wrapper e-bigger e-adaptive-demo"> 
            <div class="e-mobile-layout"> 
                <div class="e-mobile-content"> 
                    <DataGrid GridRowDirection="RowDirection.Vertical"></DataGrid> 
                </div> 
            </div> 
        </div> 
    } 
    else 
    { 
        <DataGrid GridRowDirection="RowDirection.Horizontal"></DataGrid> 
    } 
</div> 
 
@code{ 
    public string Mode { get; set; } = "Horizontal"; 
    private void ChangeVerticalDirection() 
    { 
        Mode = "Vertical"; 
        StateHasChanged(); 
    } 
    private void ChangeHorizontalDirection() 
    { 
        Mode = "Horizontal"; 
        StateHasChanged(); 
    } 
} 
[DataGrid.razor] 
 
@if (canchange) 
{ 
    <SfGrid DataSource="@Orders" AllowFiltering="true" Toolbar="@(new List<string>() { "Search" })" EnableAdaptiveUI="true" RowRenderingMode="GridRowDirection" AllowPaging="true" Height="315"> 
        <GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.Menu"></GridFilterSettings> 
        . ..  
    </SfGrid> 
} 
 
@code{ 
    public string Mode { get; set; } 
 
    public bool canchange { get; set; } 
 
    [Parameter] 
    public RowDirection GridRowDirection { get; set; } 
 
    public List<Order> Orders { get; set; } 
 
    . ..  
} 
 


Please let us know if you have any concerns. 

Regards, 
Rahul 



MA Mark replied to Rahul Narayanasamy February 21, 2022 07:54 PM UTC

Thank you! I shall try it out and let you know how it goes. 



RN Rahul Narayanasamy Syncfusion Team February 22, 2022 05:57 AM UTC

Hi Mark, 
 
Thanks for the update. 
 
We will wait to hear from you. Please let us know if you have any concerns. 
 
Regards, 
Rahul 



MR Medupi Ramaboea June 22, 2022 12:15 AM UTC

Can't this be added as a feature?
to automatically change the RowRenderingMode and set it to vertical on small screens?

This should be a default feature because  the vertical mode is suitable for small screens and the horizontal is suitable for larger screens.



NP Naveen Palanivel Syncfusion Team June 22, 2022 05:38 PM UTC

Hi Medupi,


Greetings from Syncfusion support.


We have checked your requirement and we would like to inform that we already considered as improvement and will be included in our upcoming 2022 volume 2 release.


Please find the feedback link here.

https://www.syncfusion.com/feedback/30859/render-the-adaptive-grid-based-on-small-devices-and-desktop-devices-without


Please get back to us if you need further assistance.


Regards,

Naveen Palanivel.



MR Medupi Ramaboea June 24, 2022 01:50 PM UTC

Thank you!



NP Naveen Palanivel Syncfusion Team June 28, 2022 05:09 AM UTC


Hi Medupi,


Welcome



Regards,

Naveen Palanivel.


Loader.
Up arrow icon