Skip to content

Commit 8494d9a

Browse files
committed
update after review
1 parent 1828752 commit 8494d9a

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

knowledge-base/grid-convert-descriptors-to-sql.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ ticketid: 1666625, 1653361
2222

2323
## Description
2424

25-
When using the Grid [`OnRead` event]({%slug grid-events%}#read-event) to execute SQL queries, I need to convert the Grid's filter and sort descriptors into SQL query statements. This way I can create SQL clauses for filtering and ordering items directly through SQL.
25+
When using the Grid [`OnRead` event]({%slug grid-events%}#read-event) to execute SQL queries, I need to convert the Grid's filter and sort descriptors into SQL query statements. This way I can create SQL clauses for filtering and ordering items directly through SQL.
2626

2727
This KB article also answers the following questions:
2828
- How can I convert Grid filters and sorters to SQL `WHERE` and `ORDER BY` clauses?
@@ -31,23 +31,19 @@ This KB article also answers the following questions:
3131

3232
## Solution
3333

34-
To convert the Grid's filter and sort descriptors into SQL query statements, you need to manually construct the SQL query within the `OnRead` event handler by utilizing the `args.Request.Filters` and `args.Request.Sorts` objects. Although Telerik UI for Blazor does not provide a direct method to extract the SQL query from the `DataSourceRequest`, you can achieve this manually.
34+
To convert the Grid's filter and sort descriptors into SQL query statements, you need to manually construct the SQL query within the `OnRead` event handler by utilizing the `args.Request.Filters` and `args.Request.Sorts` objects. Although Telerik UI for Blazor does not provide a direct method to extract the SQL query from the `DataSourceRequest`, you can achieve this manually.
3535

3636
The following steps outline how to achieve this:
3737

38-
1. **Handle the `OnRead` Event**: Add an `OnRead` event to your Grid and in the event handler, access the `args.Request.Filters` and `args.Request.Sorts` to construct your SQL query.
39-
40-
2. **Parse Filters**: Iterate through `args.Request.Filters` to construct the WHERE clause of your SQL query. Each filter in this collection will correspond to a column filter in the Grid.
41-
42-
3. **Parse Sort Descriptors**: Similarly, iterate through `args.Request.Sorts` to build the ORDER BY clause of your SQL query. Each sort descriptor corresponds to a column sorting in the Grid.
43-
44-
4. **Execute SQL Query**: With the constructed WHERE and ORDER BY clauses, form your complete SQL query and execute it against your database.
45-
46-
5. **Set Grid Data**: Finally, assign the result of your SQL query to the Grid by setting `args.Data`.
38+
1. Add an `OnRead` event to your Grid and in the event handler, access the `args.Request.Filters` and `args.Request.Sorts` to construct your SQL query.
39+
1. Iterate through `args.Request.Filters` to construct the `WHERE` clause of your SQL query. Each filter in this collection will correspond to a column filter in the Grid.
40+
1. Iterate through `args.Request.Sorts` to build the `ORDER BY` clause of your SQL query. Each sort descriptor corresponds to a column sorting in the Grid.
41+
1. Form your complete SQL query and execute it against your database with the constructed `WHERE` and `ORDER BY` clauses.
42+
1. Assign the result of your SQL query to the Grid by setting `args.Data`.
4743

4844
## Example
4945

50-
Below is a simplified example demonstrating how to parse filter and sort descriptors. This example does not directly execute a SQL query but outlines how to construct the WHERE and ORDER BY clauses.
46+
Below is a simplified example demonstrating how to parse filter and sort descriptors. This example does not directly execute a SQL query but outlines how to construct the `WHERE` and `ORDER BY` clauses.
5147

5248
```csharp
5349
@using System.Text

0 commit comments

Comments
 (0)