|
51 | 51 | </SfGrid> |
52 | 52 |
|
53 | 53 | @code { |
| 54 | + /// <summary> |
| 55 | + /// Implementing custom adaptor by extending the <see cref=“DataAdaptor”/> class. |
| 56 | + /// The DataGrid component support for custom data binding, which enables the binding and manipulation of data in a personalized way, using user-defined methods. |
| 57 | + /// </summary> |
54 | 58 | public class CustomAdaptor : DataAdaptor |
55 | 59 | { |
56 | 60 | public OrderData OrderService = new OrderData(); |
57 | | - // Performs data Read operation |
| 61 | + /// <summary> |
| 62 | + /// Returns the data collection after performing data operations based on request from <see cref=”DataManagerRequest”/> |
| 63 | + /// </summary> |
| 64 | + /// <param name="dataManagerRequest">DataManagerRequest containes the information regarding paging, grouping, filtering, searching which is handled on the DataGrid component side</param> |
| 65 | + /// <param name="additionalParam">An optional parameter that can be used to perform additional data operations.</param> |
| 66 | + /// <returns>The data collection's type is determined by how this method has been implemented.</returns> |
58 | 67 | public override async Task<object> ReadAsync(DataManagerRequest DataManagerRequest, string key = null) |
59 | 68 | { |
60 | 69 | IEnumerable<Order> DataSource = await OrderService.GetOrdersAsync(); |
| 70 | + // Handling Searching in Custom Adaptor. |
61 | 71 | if (DataManagerRequest.Search != null && DataManagerRequest.Search.Count > 0) |
62 | 72 | { |
63 | 73 | // Searching |
64 | 74 | DataSource = DataOperations.PerformSearching(DataSource, DataManagerRequest.Search); |
65 | 75 | } |
66 | | - if (DataManagerRequest.Sorted != null && DataManagerRequest.Sorted.Count > 0) |
67 | | - { |
68 | | - // Sorting |
69 | | - DataSource = DataOperations.PerformSorting(DataSource, DataManagerRequest.Sorted); |
70 | | - } |
| 76 | + // Handling Filtering in Custom Adaptor. |
71 | 77 | if (DataManagerRequest.Where != null && DataManagerRequest.Where.Count > 0) |
72 | 78 | { |
73 | 79 | // Filtering |
74 | 80 | DataSource = DataOperations.PerformFiltering(DataSource, DataManagerRequest.Where, DataManagerRequest.Where[0].Operator); |
75 | 81 | } |
| 82 | + // Handling Sorting in Custom Adaptor. |
| 83 | + if (DataManagerRequest.Sorted != null && DataManagerRequest.Sorted.Count > 0) |
| 84 | + { |
| 85 | + // Sorting |
| 86 | + DataSource = DataOperations.PerformSorting(DataSource, DataManagerRequest.Sorted); |
| 87 | + } |
76 | 88 | int count = DataSource.Cast<Order>().Count(); |
| 89 | + // Handling Paging in Custom Adaptor. For example, Skip is 0 and Take is equal to page size for first page. |
77 | 90 | if (DataManagerRequest.Skip != 0) |
78 | 91 | { |
79 | 92 | //Paging |
|
83 | 96 | { |
84 | 97 | DataSource = DataOperations.PerformTake(DataSource, DataManagerRequest.Take); |
85 | 98 | } |
| 99 | + // Handling Aggregates and Group in Custom Adaptor. |
86 | 100 | DataResult DataObject = new DataResult(); |
87 | | - if (DataManagerRequest.Aggregates != null || DataManagerRequest.Group != null) // Aggregation |
| 101 | + if (DataManagerRequest.Aggregates != null) // Aggregation |
88 | 102 | { |
89 | 103 | if (DataManagerRequest.Group != null) |
90 | 104 | { |
| 105 | + // For Aggregate alone |
91 | 106 | IEnumerable ResultData = DataSource.ToList(); |
92 | | - // Grouping |
| 107 | + //For Grouping |
93 | 108 | foreach (var group in DataManagerRequest.Group) |
94 | 109 | { |
95 | 110 | ResultData = DataUtil.Group<Order>(ResultData, group, DataManagerRequest.Aggregates, 0, DataManagerRequest.GroupByFormatter); |
|
102 | 117 | } |
103 | 118 | DataObject.Count = count; |
104 | 119 | DataObject.Aggregates = DataUtil.PerformAggregation(DataSource, DataManagerRequest.Aggregates); |
105 | | - |
| 120 | + //Here RequiresCount is passed from the control side itself, where ever the ondemand data fetching is needed then the RequiresCount is set as true in component side itself. |
| 121 | + // In the above case we are using Paging so datas are loaded in ondemand bases whenever the next page is clicked in DataGrid side. |
106 | 122 | return DataManagerRequest.RequiresCounts ? DataObject : (object)DataSource; |
107 | 123 | } |
| 124 | + // Handling Grouping in Custom Adaptor. |
108 | 125 | if (DataManagerRequest.Group != null) |
109 | 126 | { |
110 | 127 | IEnumerable ResultData = DataSource.ToList(); |
|
115 | 132 | } |
116 | 133 | DataObject.Result = ResultData; |
117 | 134 | DataObject.Count = count; |
| 135 | + //Here RequiresCount is passed from the control side itself, where ever the ondemand data fetching is needed then the RequiresCount is set as true in component side itself. |
| 136 | + // In the above case we are using Paging so datas are loaded in ondemand bases whenever the next page is clicked in DataGrid side. |
118 | 137 | return DataManagerRequest.RequiresCounts ? DataObject : (object)ResultData; |
119 | 138 | } |
| 139 | + //Here RequiresCount is passed from the control side itself, where ever the ondemand data fetching is needed then the RequiresCount is set as true in component side itself. |
| 140 | + // In the above case we are using Paging so datas are loaded in ondemand bases whenever the next page is clicked in DataGrid side. |
120 | 141 | return DataManagerRequest.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource; |
121 | 142 | } |
| 143 | + |
| 144 | + /// <summary> |
| 145 | + /// Inserts a new data item into the data collection. |
| 146 | + /// </summary> |
| 147 | + /// <param name="dataManager">The DataManager is a data management component used for performing data operations in applications.</param> |
| 148 | + /// <param name="record">The new record which is need to be inserted.</param> |
| 149 | + /// <param name="additionalParam">An optional parameter that can be used to perform additional data operations.</param> |
| 150 | + /// <returns>Returns the newly inserted record details.</returns> |
122 | 151 | public override async Task<object> InsertAsync(DataManager DataManager, object Value, string Key) |
123 | 152 | { |
| 153 | + // Given that the Value property consists of newly inserted record details. It can be used to insert the records into database by calling the predefined logic. |
124 | 154 | await OrderService.AddOrderAsync(Value as Order); |
125 | 155 | return Value; |
126 | 156 | } |
| 157 | + /// <summary> |
| 158 | + /// Updates an existing data item in the data collection. |
| 159 | + /// </summary> |
| 160 | + /// <param name="dataManager">The DataManager is a data management component used for performing data operations in applications.</param> |
| 161 | + /// <param name="record">The modified record which is need to be updated.</param> |
| 162 | + /// <param name="primaryColumnName">The primaryColumnName specifies the field name of the primary column.</param> |
| 163 | + /// <param name="additionalParam">An optional parameter that can be used to perform additional data operations.</param> |
| 164 | + /// <returns>Returns the updated data item.</returns> |
127 | 165 | public override async Task<object> UpdateAsync(DataManager DataManager, object Value, string keyField, string key) |
128 | 166 | { |
| 167 | + // Given that the Value property consists of modified record details. It can be used to update the changes into database by calling the predefined logic. |
129 | 168 | await OrderService.UpdateOrderAsync(Value as Order); |
130 | 169 | return Value; |
131 | 170 | } |
| 171 | + |
| 172 | + /// <summary> |
| 173 | + /// Removes a data item from the data collection. |
| 174 | + /// </summary> |
| 175 | + /// <param name="dataManager">The DataManager is a data management component used for performing data operations in applications.</param> |
| 176 | + /// <param name="primaryColumnValue">The primaryColumnValue specifies the primary column value which is needs to be removed from the grid record.</param> |
| 177 | + /// <param name="primaryColumnName">The primaryColumnName specifies the field name of the primary column.</param> |
| 178 | + /// <param name="additionalParam">An optional parameter that can be used to perform additional data operations.</param> |
| 179 | + /// <returns>Returns the removed data item.</returns> |
132 | 180 | public override async Task<object> RemoveAsync(DataManager DataManager, object Value, string keyField, string key) |
133 | 181 | { |
| 182 | + // Given that the key column is identified nullable interger type in the DataGrid, the primaryColumnValue can be utilized from Value property directly. |
134 | 183 | await OrderService.RemoveOrderAsync(Value as int?); |
135 | 184 | return Value; |
136 | 185 | } |
|
0 commit comments