Skip to content

Commit d0332fb

Browse files
committed
Extensibility points added to documentation
1 parent 31a5778 commit d0332fb

File tree

3 files changed

+84
-45
lines changed

3 files changed

+84
-45
lines changed

README.Mvc.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,7 @@ Add the `[JQDataTable]` attribute to the controller action which provides the da
77
```cs
88
public class CustomersController : Controller
99
{
10-
private AdventureWorks context;
11-
12-
public CustomersController()
13-
{
14-
this.context = new Data.AdventureWorks();
15-
}
16-
17-
// GET: Customer
10+
// GET: Customers view
1811
public ActionResult Index()
1912
{
2013
return View();
@@ -23,7 +16,8 @@ Add the `[JQDataTable]` attribute to the controller action which provides the da
2316
[JQDataTable]
2417
public ActionResult GetCustomersData()
2518
{
26-
IQueryable<Customer> data = this.context.Customers;
19+
var context = new Data.AdventureWorks();
20+
IQueryable<Customer> data = context.Customers;
2721

2822
return this.View(data);
2923
}

README.WebAPI2.md

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
## How to use
2-
Add the `[JQDataTable]` attribute to the controller action which provides the data. Return from the action View containing IQueryable collection of a strongly typed view model. On the client side configure the table for server side processing according to the jQuery Datatables documentation https://datatables.net/examples/data_sources/server_side.html.
2+
Add the `[JQDataTable]` attribute to the controller action which provides the data. Return from the action `OkNegotiatedContentResult` containing IQueryable collection of a strongly typed view model. On the client side configure the table for server side processing according to the jQuery Datatables documentation https://datatables.net/examples/data_sources/server_side.html.
33

44
### Example
55

66
#### Server
77
```cs
8-
public class CustomersController : Controller
8+
public class CustomersController : ApiController
99
{
10-
private AdventureWorks context;
11-
12-
public CustomersController()
10+
[JQDataTable]
11+
public Post GetCustomersData()
1312
{
14-
this.context = new Data.AdventureWorks();
15-
}
13+
var context = new Data.AdventureWorks();
14+
var data = context.Customers;
1615

17-
// GET: Customer
18-
public ActionResult Index()
19-
{
20-
return View();
16+
return this.Ok(data);
2117
}
18+
}
2219

23-
[JQDataTable]
24-
public ActionResult GetCustomersData()
25-
{
26-
var data = this.context.Customers.Select(x => new CustomerViewModel
27-
{
28-
CustomerID = x.CustomerID,
29-
AccountNumber = x.AccountNumber,
30-
Person = new PersonViewModel
31-
{
32-
FirstName = x.Person.FirstName,
33-
LastName = x.Person.LastName,
34-
},
35-
Store = new StoreViewModel
36-
{
37-
Name = x.Store.Name,
38-
}
39-
});
20+
public class Customer
21+
{
22+
public int CustomerId { get; set; }
23+
public Person Person { get; set; }
24+
public Store Store { get; set; }
25+
...
26+
...
27+
}
4028

41-
return this.View(data);
42-
}
29+
public class Person
30+
{
31+
...
32+
public string FirstName { get; set; }
33+
public string LastName { get; set; }
34+
...
35+
...
36+
}
37+
38+
public class Store
39+
{
40+
...
41+
public string Name { get; set; }
42+
...
4343
}
4444
```
4545

@@ -72,18 +72,17 @@ Add the `[JQDataTable]` attribute to the controller action which provides the da
7272
"proccessing": true,
7373
"serverSide": true,
7474
"ajax": {
75-
url: "@Url.Action("GetCustomersData", "Customers")",
75+
url: "api/customers",
7676
type: 'POST'
7777
},
7878
"language": {
7979
"search": "",
80-
"searchPlaceholder": "Search..."
8180
},
8281
"columns": [
83-
{ "data": "CustomerID", "searchable": false },
84-
{ "data": "Person.FirstName", "searchable": true },
85-
{ "data": "Person.LastName", "searchable": true },
86-
{ "data": "Store.Name", "searchable": true },
82+
{ "data": "CustomerID" },
83+
{ "data": "Person.FirstName" },
84+
{ "data": "Person.LastName" },
85+
{ "data": "Store.Name" },
8786
]
8887
});
8988

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Supports:
77
- Sorting;
88
- Custom filters: Less Than, Less than or equal, Greater than, Greater than or equal and Equal;
99
- Nested objects;
10+
- Option to add custom server side logic using the provided extensibility points;
1011

1112
Currently tested with Entity Framework versions 6.0.0 and 6.2.0 and Datatables version 1.10.16.
1213

@@ -161,3 +162,48 @@ The following custom filters are supported on the server side:
161162
</script>
162163
}
163164
```
165+
166+
#### Extensibility Points
167+
You can insert custom logic at any point of the data processing pipe line. The following extensibility points are provided (in order of execution):
168+
- OnDataProcessing - Called before all data processors execute.
169+
- OnSearchDataProcessing - Called before search data processor executes.
170+
- OnSearchDataProcessed - Called after search data processor executes.
171+
- OnCustomFiltersDataProcessing - Called before custom filters data processor executes.
172+
- OnCustomFiltersDataProcessed - Called after custom filters data processor executes.
173+
- OnColumnsFilterDataProcessing - Called before columns filters data processor executes.
174+
- OnColumnsFilterDataProcessed - Called after columns filters data processor executes.
175+
- OnSortDataProcessing - Called before sort data processor executes.
176+
- OnSortDataProcessed - Called after sort data processor executes.
177+
- OnPagingDataProcessing - Called before paging data processor executes.
178+
- OnPagingDataProcessed - Called after paging data processor executes.
179+
- OnDataProcessed - Called after all data processors execute.
180+
181+
##### How to use the extensibility points?
182+
Create a new class which inherrits from `JQDataTableAttribute` class. The extensibility points are implemented as virtual methods which can be overriden.
183+
###### Example
184+
```cs
185+
MyCustomDataTableAttribute : JQDataTableAttribute
186+
{
187+
// This method will modify the collection and only the customers
188+
// with even ID number will be included in the result
189+
public override void OnSearchDataProcessing(ref object data, RequestInfoModel requestInfoModel)
190+
{
191+
var dataAsQueryable = data as IQueryable<CustomerViewModel>;
192+
data = dataAsQueryable.Where(x => x.CustomerID % 2 == 0);
193+
}
194+
}
195+
```
196+
197+
Apply the new attribute on the controller action:
198+
```cs
199+
200+
CustomersController : Controller
201+
{
202+
[MyCustomDataTableAttribute]
203+
public ActionResult GetCustomersData()
204+
{
205+
...
206+
return this.View(data);
207+
}
208+
}
209+
```

0 commit comments

Comments
 (0)