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
close icon

Set DatePicker value with multiple Grids

I have a foreach loop to display 1 to many grids, and I need a datepicker filter on one of the columns. With the current code, it sets the Date on all grids, instead of the just the one grid I am picking that date on. How would I set the datepicker date on only the one grid that is being filtered?


EXAMPLE:


foreach (var dto in _invoice)

{

<SfGrid TValue="ServiceDto"

@ref="grid"

DataSource="dto.Service" >

<GridColumns>

<GridColumn Field=@nameof(ServiceDto.ServiceDate) HeaderText="Service Date" Format="d">

<FilterTemplate>

<SfDatePicker TValue="DateTime?" Value="@_selectedServiceDate" ValueChanged="HandleSelectedServiceDateFilterChange" ID="ServiceDate_filterBarcell" />

</FilterTemplate>

</GridColumn>

</GridColumns>

</SfGrid>

}



public void HandleSelectedServiceDateFilterChange(DateTime? value)

{

_selectedServiceDate = value;


if (!_selectedServiceDate.HasValue)

{

grid.ClearFiltering("ServiceDate");

}

else

{

filterDate = _selectedServiceDate.HasValue ? _selectedServiceDate.Value.ToShortDateString() : null;

grid.FilterByColumn("ServiceDate", "contains", filterDate);

}

}


3 Replies 1 reply marked as answer

SP Sarveswaran Palani Syncfusion Team February 2, 2023 02:38 AM UTC

Hi Adam,

Greetings from Syncfusion support.

From your query, we suspect that you want render FilterTemplate in specific column on dynamic column binding. We suggest you to use if condition within the filter template using column field based on your requirement. If we misunderstood your query, kindly share a issue reproducible runnable sample to us for further evaluating an issue at our end.

Regards,
Sarvesh



AS Adam Swearingen February 2, 2023 04:35 PM UTC

Thanks! I was able to get a solution using the example in this article as reference:
https://www.syncfusion.com/kb/12643/blazor-grid-how-to-create-an-array-of-grid-components-and-set-references


Marked as answer

SG Suganya Gopinath Syncfusion Team February 6, 2023 05:20 AM UTC

Adam, 

We are glad that you could find the article useful. Please get back to us for further assistance. 

We are marking this ticket as solved. 

Regards,

Suganya Gopinath. 


Loader.
Live Chat Icon For mobile
Up arrow icon