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

Indent column width when grouping with SfDataGrid

When using the grouping feature of sfDataGrid, the contained rows of each group are indented to make room for the expand arrow. I didn't need/want that arrow because my groups are always expanded and was able to remove it with a custom template in Blend. However, the indent still exists. As far as I can tell, the indenting is created with a column that I can't figure out how to access. Is there any way to remove, hide, or at least change the width of that auto generated indent column?

3 Replies

SP Sowndaiyan Paulpandi Syncfusion Team February 23, 2016 11:28 AM UTC

Hi Adam,

Thanks for contacting Syncfusion Support.

In SfDataGrid , you can achieve your requirement by customizing the style of  GridExpanderCellControl” like the below code example,

XAML


<
Window.Resources>

        <Style TargetType="syncfusion:GridExpanderCellControl">

            <Setter Property="Visibility" Value="Hidden" />

        </Style>

 </Window.Resources>



Regards,

Sowndaiyan



AR Adam Risberg February 24, 2016 07:45 AM UTC

That removes the expander arrow, but I'm trying to remove (or at least change the width of) the actual indent columns shown in the attached image. Is there any way to do that?


Attachment: DataGridColumnImage_61efee17.zip


SR Sivakumar R Syncfusion Team February 25, 2016 05:59 AM UTC

Hi Adam,

You can hide the indent columns by changing it’s width to zero. Refer the below code snippet where indent columns are hided while loading and also at runtime.

this.datagrid.GroupColumnDescriptions.CollectionChanged += GroupColumnDescriptions_CollectionChanged;

this.datagrid.ItemsSourceChanged += Datagrid_ItemsSourceChanged;


//Hides indent columns if you have grouped while loading by adding GroupColumnDescriptions

private void Datagrid_ItemsSourceChanged(object sender, GridItemsSourceChangedEventArgs e)

{

    if (e.NewItemsSource != null)

        this.HideIndentColumns();

}


//Hides indents columns when grouping at runtime  

private void GroupColumnDescriptions_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)

{

    this.HideIndentColumns();

}


private void HideIndentColumns()

{

    if (this.datagrid.View == null)

        return;

    this.datagrid.Dispatcher.BeginInvoke(new Action(() =>

    {

        int start = this.datagrid.ShowRowHeader ? 1 : 0;

        for (int i = start; i < this.datagrid.GroupColumnDescriptions.Count + start; i++)

        {

            this.datagrid.GetVisualContainer().ColumnWidths[i] = 0;

        }

    }), DispatcherPriority.ApplicationIdle);
}


Thanks,
Sivakumar

Loader.
Live Chat Icon For mobile
Up arrow icon