Skip to content

Commit

Permalink
Added None option for filter
Browse files Browse the repository at this point in the history
  • Loading branch information
mcintyre321 committed Dec 30, 2015
1 parent 59e84e3 commit 251cdd7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .vs/config/applicationhost.config
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
</site>
<site name="Mvc.JQuery.Datatables.Example" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Users\Harry\Dropbox\stuff\mvc.jquery.datatables\Mvc.JQuery.Datatables.Example" />
<virtualDirectory path="/" physicalPath="C:\Users\Harry\Dropbox\stuff\Mvc.JQuery.DataTables2\Mvc.JQuery.DataTables.Example" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:53281:localhost" />
Expand Down
14 changes: 11 additions & 3 deletions Mvc.JQuery.Datatables.Core/DataTablesFilterAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,22 @@ public DataTablesFilterAttribute(string filterType, params object[] options)
public override void ApplyTo(ColDef colDef, System.Reflection.PropertyInfo pi)
{
colDef.Filter = new FilterDef(pi.GetType());
if (filterType != null) colDef.Filter.type = filterType;
if (options != null && options.Any()) colDef.Filter.values = options;
if (filterType == "none")
{
colDef.Filter = null;
}
else
{
if (filterType != null) colDef.Filter.type = filterType;
if (options != null && options.Any()) colDef.Filter.values = options;
}
}

}

public enum DataTablesFilterType
{
None,
Select,
NumberRange,
DateRange,
Expand Down
9 changes: 6 additions & 3 deletions Mvc.JQuery.Datatables.Example/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ public DataTablesResult<UserView> GetUsers(DataTablesParam dataTableParam)
Number = user.Number,
Hired = user.Hired,
IsAdmin = user.IsAdmin,
Salary = user.Salary
Salary = user.Salary,
Thumb = "https://randomuser.me/api/portraits/thumb/men/" + user.Id + ".jpg"
}), dataTableParam,
uv => new
{
Name = "<b>" + uv.Name + "</b>",
Hired = uv.Hired == null ? "&lt;pending&gt;" : uv.Hired.Value.ToShortDateString() + " (" + FriendlyDateHelper.GetPrettyDate(uv.Hired.Value) + ") "
Hired = uv.Hired == null ? "&lt;pending&gt;" : uv.Hired.Value.ToShortDateString() + " (" + FriendlyDateHelper.GetPrettyDate(uv.Hired.Value) + ") ",
Thumb = "<img src='" + uv.Thumb + "' />"
});
}

Expand Down Expand Up @@ -87,7 +89,8 @@ public class UserView
[DataTablesExclude]
public string ThisColumnIsExcluded { get { return "asdf"; } }


[DataTablesFilter(DataTablesFilterType.None)]
public string Thumb { get; set; }
}

public class DefaultToStartOf2014Attribute : DataTablesAttributeBase
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,9 @@ If you have a feature request, bug, or a patch, please could you add an example
[![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)

> If you have found this project useful, please consider contributing some documentation - it's the biggest weakness!

THANKS
------

To https://randomuser.me/ for the image thumbnails used in the example site

0 comments on commit 251cdd7

Please sign in to comment.