Frozen columns with allow resezing cause losing grid width

Hi!

I've a Grid like this:

@(Html.EJS().Grid("MyGrid")
.AllowTextWrap(true)
.AllowPaging(false)
.AllowSelection(false)
.DataSource((IEnumerable<object>)Model.Data)
.AllowResizing(true)
.Columns(col =>
{
col.Template("#myTemplate").Width(20).TextAlign(TextAlign.Center).Add();
col.Field("ColumnA").HeaderText("Column A").Width(50).Add();
col.Field("ColumnB").HeaderTemplate("#emptyTemplate").Template("#symbolTemplate").Width(20).Add();
col.Field("ColumnC").HeaderText("ColumnC").Width(60).Visible(isVisibleColumnC).Add();
col.Field("ColumnD").HeaderText("ColumnD").Width(70).Add();
col.Field("ColumnE").HeaderText("ColumnE").Width(40).Add();
col.Field("ColumnF").HeaderText("ColumnF").Width(60).Add();
col.Field("ColumnG").HeaderText("ColumnG").Width(60).Add();
col.HeaderText("ColumnH").Template("#mySecondTemplate").Width(40).Visible(isVisibleColumnH).Add();
col.Field("ColumnI").HeaderText("ColumnI").Template("#anotherTemplate").Width(40).Add();
})
.Height(430)
.AllowSorting(true)
.EnableVirtualization(true)
.EnableHover(false)
.EnableHeaderFocus(true)
.LoadingIndicator(l => { l.IndicatorType(Syncfusion.EJ2.Grids.IndicatorType.Shimmer); })
.Locale(Model.MyLanguage)
.ShowColumnMenu(true)
.AllowGrouping()
.RowHeight(30)
.AllowReordering()
.AllowFiltering()
.FilterSettings(filter => { filter.Type(Syncfusion.EJ2.Grids.FilterType.Excel); })
.AllowExcelExport(true).AllowPdfExport(true)
.Render()
)

Using a custom JS function (triggered by an classic button into the page containing the grid) I froze the grid columns.

My JS code is:

...
var grid = document.getElementById(gridName).ej2_instances[0];

// Do some stuff

grid.frozenColumns = columnToFreeze; // It's a positive integer number

grid.refresh();
grid.refreshColumns();
grid.refreshHeader();
} // End of function

When my function terminates, the grid lose Its width (from 1908px goes to 480px): the columns became smaller (less than a classic autofit).

I've noticed that if I disallow "AllowResizing" property, the problem doesn't occour.
Following code works fine:

...
var grid = document.getElementById(gridName).ej2_instances[0];

// Do some stuff
grid.allowResizing = false;
grid.frozenColumns = columnToFreeze; // It's a positive integer number

grid.refresh();
grid.refreshColumns();
grid.refreshHeader();
} // End of function

If I try to re-enable the "AllowResizing" property before leave the function, the problem occours again.
This code doesn't work:

...
var grid = document.getElementById(gridName).ej2_instances[0];

// Do some stuff
grid.allowResizing = false;
grid.frozenColumns = columnToFreeze; // It's a positive integer number

grid.refresh();
grid.refreshColumns();
grid.refreshHeader();

grid.allowResizing = true;
} // End of function

I'm using the 27.1.56 DLL version.


May be I'm missing something, but I don't see wht.

Thanks for your support!

Ragards,
Emanuele


7 Replies 1 reply marked as answer

JC Joseph Christ Nithin Issack Syncfusion Team November 4, 2024 11:47 AM UTC


Hi Emanuele,


   Greetings from Syncfusion support.


   You have mentioned that when you enable column resizing and dynamically freeze columns in EJ2 Grid, the width of the columns is reduced. We would like to inform you that the mentioned issue has been fixed in version 27.1.53. However, you have mentioned that you are using the 27.1.56 DLL version and still you are facing the issue, we suspect that you might have missed upgrading the script and CSS in the _Layout.cshtml file. Please ensure to update the script and CSS to the latest version.


Please refer to the below code example:


 

[_Layout.cshtml]

 

    @* Syncfusion Essential JS 2 Styles *@

    <link rel="stylesheet" rel='nofollow' href=https://cdn.syncfusion.com/ej2/27.1.53/material.css />

 

    @* Syncfusion Essential JS 2 Scripts *@

    <script src=https://cdn.syncfusion.com/ej2/27.1.53/dist/ej2.min.js></script>

 


Regards,

Joseph I.



ED Emanuele Dabove replied to Joseph Christ Nithin Issack November 6, 2024 03:19 PM UTC

Hi Joseph.


Thanks for your support: I've downloaded the ej2.min.js (version 27.1.56) and It works!


I would like to add another question, if possible: after I've upgrated the ej2.min.js, I found a different problem.
Through a normal button I take the grid configuration using this JS:


var grid = document.getElementById(gridName).ej2_instances[0];
var persistData = JSON.parse(grid.getPersistData());


and I save It into a SQL DB (without any modification).

If I freeze a column, I save the configuration and then I reload the grid trying to apply the configuration using this JS:


var gridColumnsState = Object.assign([], grid.getColumns());
var state = JSON.parse(stateString); // stateString contains the JSON read from the DB
grid.setProperties(state);


I obtain this error:


Screenshot_20241106_161557.png


Am I missing something?


Thanks for your support!


Regards,
Emanuele




JC Joseph Christ Nithin Issack Syncfusion Team November 8, 2024 04:43 AM UTC


Hi Emanuele,


  You can use the State Persistence feature to store and restore the grid's state, allowing it to maintain its configuration when the page is reloaded or revisited. We've provided detailed information on this in the documentation linked below. Please refer to it for more details.


Documentation: State Persistence in ASP.NET MVC Grid Component


Additionally, you may find our blog helpful, which offers a comprehensive explanation and step-by-step instructions.


Blog: Enhance User Experience: Preserve ASP.NET Core Grid Layout Settings


If you still face the issue, kindly share the below details for further validation.


  • Are you using any foreign key columns in your grid.
  • You are having multiple columns with templates, ensure if you are facing the same issue when the template columns are removed. Please refer the below documentation if you would like to persist the template columns also.
    Documentation: Add to Persist in ASP.NET MVC Grid Component
  • Share the video demo or the pictorial representation of the issue you are facing.
  • Share the Sycnfusion package version you are using.


ED Emanuele Dabove November 13, 2024 04:35 PM UTC

Hi Joseph.

Thanks for your reply and your suggestions.


Below some response:

  • "Are you using any foreign key columns in your grid."
    No, I'm not using any foreign key.
  • "...ensure if you are facing the same issue when the template columns are removed..."
    I've removed all the templates columns, but the problem persists.
  • "Share the Sycnfusion package version you are using"
    I'm using the Syncfusion version 27.1.56 both DLL and ej2.min.js

I cannot provide a video demo, sorry.

I need to save the grid state on a SQL DB and It works fine. The problem occours if I froze a column, I save the grid state and then I reload it.
I obtain the JavaScript error posted in my previous reply.

The code is the same that I've posted.

Thanks for your patient.

Regards,
Emanuele


JC Joseph Christ Nithin Issack Syncfusion Team November 21, 2024 08:31 AM UTC


Hi Emanuele,


When you restore the grid's state after dynamically adding frozen columns and reloading the page, a script error occurs. Upon reviewing the code example you provided, it appears you are using the `setProperties` method to apply the saved grid configuration to the EJ2 Grid. We suspect that the `columnModel` is not properly set to the grid. Therefore, we recommend calling the `freezeRefresh` method of the EJ2 Grid after configuring it.


Please refer the below code example:


 

var grid = document.getElementById("Grid").ej2_instances[0];

 

var state = JSON.parse(result); // get the data

 

grid.setProperties(state, true); // restore the Grid state, passing true as parameter stops the internal refresh of the grid. 

grid.freezeRefresh(); // refresh the grid by reloading all the modules and re-rendering the entire grid.

 




Marked as answer

ED Emanuele Dabove December 4, 2024 08:59 AM UTC

Hi Joseph.

Sorry for the delay with the response.


I tried your suggestions:

grid.setProperties(state, true);
grid.freezeRefresh();


and It works!


Thanks for your patient and support.


Best regards,
Emanuele



VK Vasanthakumar K Syncfusion Team December 4, 2024 01:16 PM UTC

Hi Emanuele Dabove,


We are glad to hear that our provided solution has been helpful in resolving your customization handling issue of restoring the grid's state after dynamically adding frozen columns on your application.


Please feel free to reach out if you have any further queries regarding this forum. As always, we are happy to assist you.


Regards,

Vasanthakumar K


Loader.
Up arrow icon