Skip to content

Commit e065710

Browse files
committed
Added FilterDef concept, Hide header row
1 parent 2acbd5a commit e065710

File tree

7 files changed

+152
-98
lines changed

7 files changed

+152
-98
lines changed

Mvc.JQuery.Datatables.Templates/Content/jquery.dataTables.columnFilter.js

+15-12
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

6363
// use only filtered rows
6464
if (bFiltered == true) aiRows = oSettings.aiDisplay;
65-
// use all rows
65+
// use all rows
6666
else aiRows = oSettings.aiDisplayMaster; // all row numbers
6767

6868
// set up data array
@@ -76,10 +76,10 @@
7676
// ignore empty values?
7777
if (bIgnoreEmpty == true && sValue.length == 0) continue;
7878

79-
// ignore unique values?
79+
// ignore unique values?
8080
else if (bUnique == true && jQuery.inArray(sValue, asResultData) > -1) continue;
8181

82-
// else push the value onto the result data array
82+
// else push the value onto the result data array
8383
else asResultData.push(sValue);
8484
}
8585

@@ -139,7 +139,7 @@
139139
iLastFilterLength = 0;
140140
var iCurrentFilterLength = this.value.length;
141141
if (Math.abs(iCurrentFilterLength - iLastFilterLength) < iFilterLength
142-
//&& currentFilter.length == 0 //Why this?
142+
//&& currentFilter.length == 0 //Why this?
143143
) {
144144
//Cancel the filtering
145145
return;
@@ -325,7 +325,7 @@
325325
var index = iColumn;
326326
var currentFilter = oTable.fnSettings().aoPreSearchCols[i].sSearch;
327327

328-
var r = '<select class="search_init select_filter"><option value="" class="search_init">' + sLabel + '</option>';
328+
var r = '<select class="search_init select_filter"><option value="" class="search_init"></option>';
329329
var j = 0;
330330
var iLen = aData.length;
331331
for (j = 0; j < iLen; j++) {
@@ -404,7 +404,7 @@
404404
if (properties.sFilterButtonText != null || properties.sFilterButtonText != undefined) {
405405
labelBtn = properties.sFilterButtonText;
406406
} else {
407-
labelBtn = label;
407+
labelBtn = label || "filter";
408408
}
409409

410410
var relativeDivWidthToggleSize = 10;
@@ -437,7 +437,7 @@
437437
r += divRowDef;
438438

439439
var storedValues = oTable.fnSettings().aoPreSearchCols[i].sSearch;
440-
440+
441441
var previousValues = storedValues ? storedValues.split("|") : [];
442442
for (j = 0; j < iLen; j++) {
443443

@@ -495,7 +495,7 @@
495495
//height: 140,
496496
autoOpen: false,
497497
//show: "blind",
498-
hide: "blind",
498+
//hide: "blind",
499499
buttons: [{
500500
text: "Reset",
501501
click: function () {
@@ -513,15 +513,16 @@
513513
text: "Close",
514514
click: function () { $(this).dialog("close"); }
515515
}
516-
]
516+
]
517517
});
518518

519519

520520
$('#' + buttonId).click(function () {
521521

522522
$('#' + checkToggleDiv).dialog('open');
523523
var target = $(this);
524-
$('#' + checkToggleDiv).dialog("widget").position({ my: 'top',
524+
$('#' + checkToggleDiv).dialog("widget").position({
525+
my: 'top',
525526
at: 'bottom',
526527
of: target
527528
});
@@ -533,7 +534,8 @@
533534

534535
fnOnFiltered = function () {
535536
var target = $('#' + buttonId);
536-
$('#' + checkToggleDiv).dialog("widget").position({ my: 'top',
537+
$('#' + checkToggleDiv).dialog("widget").position({
538+
my: 'top',
537539
at: 'bottom',
538540
of: target
539541
});
@@ -612,7 +614,8 @@
612614

613615
$(sFilterRow + " th", oTable).each(function (index) {
614616
i = index;
615-
var aoColumn = { type: "text",
617+
var aoColumn = {
618+
type: "text",
616619
bRegex: false,
617620
bSmart: true,
618621
iFilterLength: 0

Mvc.JQuery.Datatables.Templates/Mvc.JQuery.Datatables.Templates.csproj

+6-1
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,12 @@
848848
<Content Include="Content\jquery.dataTables.columnFilter.js" />
849849
<Content Include="Views\Shared\DataTable.cshtml" />
850850
</ItemGroup>
851-
<ItemGroup />
851+
<ItemGroup>
852+
<ProjectReference Include="..\Mvc.JQuery.Datatables\Mvc.JQuery.Datatables.csproj">
853+
<Project>{389ade94-7c32-4885-812e-68a2a74c82d8}</Project>
854+
<Name>Mvc.JQuery.Datatables</Name>
855+
</ProjectReference>
856+
</ItemGroup>
852857
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
853858
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
854859
Other similar extension points exist, see Microsoft.Common.targets.

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

+19-15
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
@using Mvc.JQuery.Datatables
1+
@using System.Data.Odbc
2+
@using System.Linq
3+
@using Mvc.JQuery.Datatables
24
@model DataTableConfigVm
3-
45
<table id="@Model.Id" class="display @(Model.TableClass ?? DataTableConfigVm.DefaultTableClass ?? "")" >
56
<thead>
6-
<tr>
7-
@foreach (var column in Model.Columns)
8-
{
9-
<th>@column.DisplayName</th>
10-
}
11-
</tr>
12-
@if (Model.ColumnFilter)
7+
@if (Model.ColumnFilter && Model.Columns.Any(c => c.Visible && c.Filter != null))
8+
{
9+
<tr>
10+
@foreach (var column in Model.Columns)
11+
{
12+
<th></th>
13+
}
14+
</tr>
15+
}
16+
@if (!Model.HideHeaders)
1317
{
1418
<tr>
1519
@foreach (var column in Model.Columns)
@@ -67,15 +71,15 @@
6771
,"fnDrawCallback": @Html.Raw(Model.DrawCallback)
6872
</text>
6973
}
70-
});
74+
});
7175
@if (Model.ColumnFilter)
7276
{
7377
<text>
74-
dt.columnFilter({
75-
sPlaceHolder: "head:before",
76-
aoColumns: [@Html.Raw(Model.ColumnFiltersString)]
77-
});
78-
</text>
78+
dt.columnFilter({
79+
sPlaceHolder: "head:after",
80+
aoColumns: @Html.Raw(Model.ColumnFiltersString)
81+
});
82+
</text>
7983
}
8084
})();
8185
</script>

Mvc.JQuery.Datatables/ColDef.cs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
3+
namespace Mvc.JQuery.Datatables
4+
{
5+
public class ColDef
6+
{
7+
protected internal ColDef(Type type)
8+
{
9+
Type = type;
10+
Filter = new FilterDef(Type);
11+
}
12+
13+
public string Name { get; set; }
14+
public string DisplayName { get; set; }
15+
public bool Visible { get; set; }
16+
public bool Sortable { get; set; }
17+
public Type Type { get; set; }
18+
public bool Searchable { get; set; }
19+
public SortDirection SortDirection { get; set; }
20+
public string MRenderFunction { get; set; }
21+
public FilterDef Filter { get; set; }
22+
23+
public static ColDef Create(string name, string p1, Type propertyType, bool visible = true, bool sortable = true,
24+
SortDirection sortDirection = SortDirection.None, string mRenderFunction = null)
25+
{
26+
return new ColDef(propertyType)
27+
{
28+
Name = name,
29+
DisplayName = p1,
30+
Visible = visible,
31+
Sortable = sortable,
32+
SortDirection = sortDirection,
33+
MRenderFunction = mRenderFunction,
34+
};
35+
}
36+
37+
38+
}
39+
}

0 commit comments

Comments
 (0)