You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: knowledge-base/grid-convert-descriptors-to-sql.md
+8-12Lines changed: 8 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ ticketid: 1666625, 1653361
22
22
23
23
## Description
24
24
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.
26
26
27
27
This KB article also answers the following questions:
28
28
- 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:
31
31
32
32
## Solution
33
33
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.
35
35
36
36
The following steps outline how to achieve this:
37
37
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`.
47
43
48
44
## Example
49
45
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.
0 commit comments