Is it possible to have AutoFitAll function of the ContextMenu to leave no white space?

Hello,

I have noticed that when clicking "Autofit all columns" from the context menu that the columns are sized correctly to accommodate the contents of each column but this can leave whitespace at the end of the grid:




Is it possible to get the grid to set the column widths slightly wider in order to utilise this white space?


Thank


8 Replies

MS Monisha Saravanan Syncfusion Team February 7, 2022 12:52 PM UTC

Hi Chuck, 

Greetings from Syncfusion support. 

We have validated your query with the provided screenshot. If we enable Autofit for all columns, then the columns gets autofit based on the data present in the column. So the empty space will be shown after all the columns when we used AutoFit property. This is default behavior of Grid. Find the below documentation for your reference. 

Reference

Please let us know if we misunderstood your query or if you have any concerns. 

Regards, 
Monisha 



CR Chuck Richardson February 7, 2022 02:21 PM UTC

Hi Monisha,


Thanks for the quick reply. I appreciate that the grid is behaving as documented. However, the problem this causes is that if you have EnablePersistance="true" and you choose the option to Auto Fit All then navigate away and back again, the columns change size.


To reproduce you can use the following grid code:


<SfGrid @ref="DefaultGrid" DataSource="@Orders"

    AllowSorting="true"

    AllowResizing="true"

    ID="TestAutoResize"

    EnablePersistence="true"

    ContextMenuItems="@(new List<object>() { "AutoFit", "AutoFitAll"})"

>

    <GridColumns>

        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>

        <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn>

        <GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn>

        <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>

    </GridColumns>

</SfGrid>


@code{

    private SfGrid<Order> DefaultGrid;


    public List<Order> Orders { get; set; }


    protected override void OnInitialized()

    {

        Orders = Enumerable.Range(1, 20).Select(x => new Order()

        {

            OrderID = 1000 + x,

            CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)],

            Freight = 2.1 * x,

            OrderDate = DateTime.Now.AddDays(-x),

        }).ToList();

    }


    public class Order

    {

        public int? OrderID { get; set; }

        public string CustomerID { get; set; }

        public DateTime? OrderDate { get; set; }

        public double? Freight { get; set; }

    }



After Auto Fit All Columns the grid looks like this:


After navigating to Home and back again it looks like this:



I believe this is because on initialising it is trying to make use of all of the space available to it rather than leaving white space. This is what I would like to the Auto Fit All Columns to do so that as the user navigates back to the grid the columns are still sized as they were previously.


I hope that is clear.


Thanks,


Chuck



MS Monisha Saravanan Syncfusion Team February 9, 2022 04:22 AM UTC

Hi Chuck, 

Thanks for your update 

We have analyzed your query and we found that you have created separate forum for the same query (forum), please follow up with the mentioned thread for further follow ups. 

Regards, 
Monisha  



CR Chuck Richardson February 11, 2022 10:13 AM UTC

Hi Monisha,


172610 is related but is a different issue. in 172610 I have asked how to get the AutoFit All behaviour to use the white space.


While this form entry 172611 is about the fact that when you use AutoFit All with EnablePersistence=true and navigate away from the grid and back again, it does not set the column widths to what they were after using AutoFit All.


I hope the distinction between the two forum entries is clear.


Thanks,


Chuck



MS Monisha Saravanan Syncfusion Team February 14, 2022 02:41 PM UTC

Hi Chuck, 

Thanks for your update. 

Query: “Is it possible to get the grid to set the column widths slightly wider in order to utilize this white space?” 
 
Currently we are validating the reported query at our end. We need some more time to analyze your query. So we will update you the further details in two business days on or before (16th February 2022).  

For the next Query regarding persistence with autofit we suggest you to follow up on this forum

Kindly get back to us if you have further queries. 

Regards, 
Monisha 
 
 



MS Monisha Saravanan Syncfusion Team February 15, 2022 03:05 PM UTC

Hi Chuck, 

Thanks for your patience. 

Currently we don't have support to use the whitespace during Autofit all function. We have considered it as a usability improvement and logged a task “Need to provide support to prevent white space when using Autofit all”. At the planning stage for every release cycle, we review all open features and identify features for implementation based on specific parameters including product vision, technological feasibility, and customer interest. And this improvement will be included in any of our upcoming releases.  
  
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.  
     

You can also communicate with us regarding the open improvement any time using our above feedback report page. We do not have immediate plan to implement this improvement and it will be included in any of our upcoming releases. Please cast your vote to make it count. So that we will prioritize the improvement for every release based on demands. 

Regards, 
Monisha 



CR Chuck Richardson February 15, 2022 08:18 PM UTC

Hi Monisha,


Thanks for logging the use of white space as a potential future enhancement.


In the meantime, how can I get the grid to size the columns the way it does when it renders the first time? In other words, if a user changes grid column sizes and then wants to revert back to how the grid displayed when they first landed on the page, how I can I achieve this?


Thanks,


Chuck



MS Monisha Saravanan Syncfusion Team February 16, 2022 09:21 AM UTC

Hi Chuck, 

Sorry for the inconvenience. 

Currently we don’t have any workaround/possible solution to maintain the grid state after changing the column sizes. Instead we suggest you to remove the Grid component and re render the grid again to get the initial grid rendered state. 

<SfButton @onclick="Refresh">Reset</SfButton> 
 
@if (canRender) 
{ 
 
    <SfGrid ID="GridSizeNew" @ref="Grid" DataSource="@Orders" AllowResizing="true" AllowPaging="true" ContextMenuItems="@(new List<object>() { "AutoFit", "AutoFitAll"})" AllowGrouping="true" AllowReordering="true"> 
        <GridColumns> 
... 
        </GridColumns> 
   </SfGrid> 
} 
 
@code{ 
    public bool canRender = true; 
   public async Task Refresh() 
    { 
        if (canRender) 
        { 
            canRender = false; 
        } 
        else 
        { 
            canRender = true;  
        } 
     } 
   } 


Kindly get back to us if you have further queries. 

Regards, 
Monisha 


Loader.
Up arrow icon