Skip to content

Commit 540c28d

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 8e9324e + 2d03c0f commit 540c28d

File tree

4 files changed

+56
-34
lines changed

4 files changed

+56
-34
lines changed

Mvc.JQuery.Datatables.Templates/Views/Shared/DataTable.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
<script type="text/javascript">
3535
(function setDataTable() {
36-
if(!window.jQuery) {
36+
if(!window.jQuery || !$.fn.DataTable) {
3737
setTimeout(setDataTable, 100);
3838
return;
3939
}

Mvc.JQuery.Datatables/RegisterDatatablesModelBinder.cs.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Web.WebPages;
44
using Mvc.JQuery.Datatables;
55

6-
[assembly: PreApplicationStartMethod(typeof(RegisterDatatablesModelBinder), "Start")]
6+
[assembly: PreApplicationStartMethod(typeof($rootnamespace$.RegisterDatatablesModelBinder), "Start")]
77

88
namespace $rootnamespace$ {
99
public static class RegisterDatatablesModelBinder {

Mvc.JQuery.Datatables/StringTransformers.cs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,43 @@
55

66
namespace Mvc.JQuery.Datatables
77
{
8-
static class StringTransformers
8+
public static class StringTransformers
99
{
1010
internal static object GetStringedValue(Type propertyType, object value)
1111
{
12-
foreach (var transformer in Transformers)
13-
{
14-
var result = transformer(propertyType, value);
15-
if (result != null) return result;
16-
}
12+
if (Transformers.ContainsKey(propertyType))
13+
return Transformers[propertyType](propertyType, value);
1714
return (value as object ?? "").ToString();
1815
}
19-
private static readonly List<StringTransformer> Transformers = new List<StringTransformer>()
16+
17+
static StringTransformers()
2018
{
21-
Guard<DateTimeOffset>(dateTimeOffset => dateTimeOffset.ToLocalTime().ToString("g")),
22-
Guard<DateTime>(dateTime => dateTime.ToLocalTime().ToString("g")),
23-
Guard<IHtmlString>(s => s.ToHtmlString()),
24-
Guard<IEnumerable<string>>(s => s.ToArray()),
25-
Guard<IEnumerable<int>>(s => s.ToArray()),
26-
Guard<IEnumerable<long>>(s => s.ToArray()),
27-
Guard<IEnumerable<decimal>>(s => s.ToArray()),
28-
Guard<IEnumerable<bool>>(s => s.ToArray()),
29-
Guard<IEnumerable<double>>(s => s.ToArray()),
30-
Guard<IEnumerable<object>>(s => s.Select(o => GetStringedValue(o.GetType(), o)).ToArray()),
31-
Guard<bool>(s => s),
32-
Guard<object>(o => (o ?? "").ToString())
33-
};
19+
RegisterFilter<DateTimeOffset>(dateTimeOffset => dateTimeOffset.ToLocalTime().ToString("g"));
20+
RegisterFilter<DateTime>(dateTime => dateTime.ToString("g"));
21+
RegisterFilter<IHtmlString>(s => s.ToHtmlString());
22+
RegisterFilter<IEnumerable<string>>(s => s.ToArray());
23+
RegisterFilter<IEnumerable<int>>(s => s.ToArray());
24+
RegisterFilter<IEnumerable<long>>(s => s.ToArray());
25+
RegisterFilter<IEnumerable<decimal>>(s => s.ToArray());
26+
RegisterFilter<IEnumerable<bool>>(s => s.ToArray());
27+
RegisterFilter<IEnumerable<double>>(s => s.ToArray());
28+
RegisterFilter<IEnumerable<object>>(s => s.Select(o => GetStringedValue(o.GetType(), o)).ToArray());
29+
RegisterFilter<bool>(s => s);
30+
RegisterFilter<object>(o => (o ?? "").ToString());
31+
}
3432

35-
public delegate object GuardedValueTransformer<TVal>(TVal value);
33+
private static readonly Dictionary<Type, StringTransformer> Transformers = new Dictionary<Type, StringTransformer>();
3634

35+
public delegate object GuardedValueTransformer<TVal>(TVal value);
3736

3837
public delegate object StringTransformer(Type type, object value);
3938

4039
public static void RegisterFilter<TVal>(GuardedValueTransformer<TVal> filter)
4140
{
42-
Transformers.Add(Guard<TVal>(filter));
41+
if (Transformers.ContainsKey(typeof(TVal)))
42+
Transformers[typeof(TVal)] = Guard(filter);
43+
else
44+
Transformers.Add(typeof(TVal), Guard(filter));
4345
}
4446

4547
private static StringTransformer Guard<TVal>(GuardedValueTransformer<TVal> transformer)
@@ -64,4 +66,4 @@ public static Dictionary<string, object> TransformDictionary(Dictionary<string,
6466
return output;
6567
}
6668
}
67-
}
69+
}

README.md

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
1-
ASP MVC Helpers for working with the amazing Jquery DataTables plugin. See http://mvcjquerydatatables.apphb.com/ for an example
1+
turn IQueryables into datagrids
2+
----------------------------------
23

3-
http://nuget.org/packages/Mvc.JQuery.Datatables
4-
5-
The code here is based on code from http://code.google.com/p/datatables-asp-mvc/
4+
> Install-Package Mvc.JQuery.Datatables
65
7-
If you have a feature request, bug, or a patch, please could you add an example page on a fork demonstrating the problem or feature. Thanks!
6+
> Install-Package Mvc.JQuery.Datatables.Templates *
87
9-
[![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=mcintyre321&url=https://github.com/mcintyre321/mvc.jquery.datatables&title=Mvc.JQuery.DataTables&language=&tags=github&category=software)
108

11-
Example output:
9+
[Demo site](http://mvcjquerydatatables.apphb.com/)
10+
![Example](http://snag.gy/FQFdn.jpg)
1211

12+
- turn any IQueryable into a live datagrid. Tested with:
13+
- Linq To Objects
14+
- Entity Framework
15+
- Lucene.Net.Linq
16+
- wraps the very comprehensive jquery datatables plugin. Supported features:
17+
- Filtering (text, date range (with datepicker), number ranges, choose from dropdown, multiple values using checkboxes)
18+
- Sorting (configurable per column)
19+
- Paging (choose page size options, or fix them)
20+
- Customer column rendering
21+
- Custom positioning of filters (e.g. you could move them above the table)
22+
- Localization
23+
- TableTools support (PDF/Excel export)
24+
- Attribute based configuration (optional)
25+
- Can be run from dll
26+
27+
*skip this if using EmbeddedResourceVirtualPathProvider
28+
29+
30+
See the test page and example project for info on how to use
1331

14-
![Example](http://snag.gy/FQFdn.jpg)
32+
http://nuget.org/packages/Mvc.JQuery.Datatables
1533

34+
The code here is based on code from http://code.google.com/p/datatables-asp-mvc/
1635

17-
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/mcintyre321/mvc.jquery.datatables/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
36+
If you have a feature request, bug, or a patch, please could you add an example page on a fork demonstrating the problem or feature. Thanks!
1837

38+
[![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=mcintyre321&url=https://github.com/mcintyre321/mvc.jquery.datatables&title=Mvc.JQuery.DataTables&language=&tags=github&category=software)

0 commit comments

Comments
 (0)