SfGrid Search

How can I set the skip value to 0 in SfGrid when a value is entered in the Search text and Enter is pressed?


5 Replies

PS Prathap Senthil Syncfusion Team May 3, 2024 02:17 AM UTC

Hi Buza,

Before proceeding with the reporting of the problem, we require some additional clarification from your end. Please share the following details to proceed further on our end:

  • Are you currently using a custom adaptor for your DataGrid?
  • Could you provide more details on when and how you want the skip value to be changed?
  • Could you please share a simple issue-reproducible sample?
  • Are you looking for a solution that updates the skip value automatically when the user enters a search term, and presses Enter?
  • Are you currently using a custom adapter, and do you want to know how to dynamically change the skip value when the search input is used

The details requested above will be very helpful in validating the reported query on our end and providing a solution as soon as possible. Thanks for your understanding.

Regards,
Prathap S



BU Buza May 3, 2024 06:08 AM UTC

Hi Prathap,

  • Are you currently using a custom adaptor for your DataGrid?
    I'm using Adaptors.UrlAdaptor.
  • Could you provide more details on when and how you want the skip value to be changed?
    Updates the skip value automatically to 0 when the user enters a search term, and presses Enter
  • Could you please share a simple issue-reproducible sample?
    From DataManagerRequest, I create a dynamic SQL query
    SET @Query = N'SELECT V.PkCity
    , V.City
    , V.CountryName
    , TotalRows = COUNT(*) OVER ()
    FROM Data.vCity AS V '
    + ISNULL(@Where, '') + N' ORDER BY V.City OFFSET '
    + CAST(@Skip AS NVARCHAR(100)) + N' ROWS FETCH NEXT '
    + CAST(@PageSize AS NVARCHAR(100)) + N' ROWS ONLY';

    The parameters in the procedure are:
    @Where NVARCHAR(500) = N'WHERE CountryName = ''Brazil'''
    , @Skip INT = 0
    , @PageSize INT = 10;

    As the user navigates through the pages @Skip is increasing.
    When the user enters a new search, @skip remains the same, only the where clause changes.
    For example, if a new search only returns 20 records and skip is at 50, we won't get any data.

    Regards,
    Buza




PS Prathap Senthil Syncfusion Team May 6, 2024 11:53 AM UTC

Based on your requirements, we suggest using the 'Searching' event to set the skip value as 0 whenever searching. By adjusting the skip value accordingly, you can achieve your desired outcome. Please refer to the code snippet and documentation below for more details.

<SfGrid DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Search" })">

    <GridEvents Searching="SearchingHandler" TValue="Order"></GridEvents>

</SfGrid>
public
int SKipValue { get; set; }

 public void SearchingHandler(SearchingEventArgs args)

{

     SKipValue = 0;

     // Here, you can customize your code.

}

 


Reference: https://blazor.syncfusion.com/documentation/datagrid/events#searching




BU Buza May 7, 2024 06:54 PM UTC

Hi Prathap,

The Searching="SearchingHandler" event doesn't have an effect if Adaptor="Adaptors.UrlAdaptor". The only solution I found is the OnActionBegin="ActionBegin" event.

private void ActionBegin(ActionEventArgs<CityModel> args)

{

    if (args.RequestType == Syncfusion.Blazor.Grids.Action.Searching || args.RequestType == Syncfusion.Blazor.Grids.Action.Filtering)

    {

        args.CurrentPage = 1;

    }

}




PS Prathap Senthil Syncfusion Team May 8, 2024 12:35 PM UTC

Thanks for the update,


We are happy to hear that the issue you reported has been resolved at your end. We are closing the thread now.


Loader.
Up arrow icon