Skip to content

Commit 3515b20

Browse files
committed
New column properties (attributes) for CSS Class
CssClass and CssClassHeader
1 parent 0acae3f commit 3515b20

File tree

5 files changed

+18
-3
lines changed

5 files changed

+18
-3
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<tr>
1919
@foreach (var column in Model.Columns)
2020
{
21-
<th>@column.DisplayName</th>
21+
<th class="@column.CssClassHeader">@column.DisplayName</th>
2222
}
2323
</tr>
2424
}

Mvc.JQuery.Datatables/ColDef.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ protected internal ColDef(Type type)
1616
public bool Sortable { get; set; }
1717
public Type Type { get; set; }
1818
public bool Searchable { get; set; }
19+
public String CssClass { get; set; }
20+
public String CssClassHeader { get; set; }
1921
public SortDirection SortDirection { get; set; }
2022
public string MRenderFunction { get; set; }
2123
public FilterDef Filter { get; set; }
2224

2325
public static ColDef Create(string name, string p1, Type propertyType, bool visible = true, bool sortable = true,
24-
SortDirection sortDirection = SortDirection.None, string mRenderFunction = null)
26+
SortDirection sortDirection = SortDirection.None, string mRenderFunction = null, string pCssClass = "",
27+
string pCssClassHeader = "")
2528
{
2629
return new ColDef(propertyType)
2730
{
@@ -31,6 +34,8 @@ public static ColDef Create(string name, string p1, Type propertyType, bool visi
3134
Sortable = sortable,
3235
SortDirection = sortDirection,
3336
MRenderFunction = mRenderFunction,
37+
CssClass = pCssClass,
38+
CssClassHeader = pCssClassHeader,
3439
};
3540
}
3641

Mvc.JQuery.Datatables/DataTableConfigVm.cs

+6
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ private static string convertColumnDefsToJson(IEnumerable<ColDef> columns)
252252
var nonVisibleColumns = columns.Select((x, idx) => x.Visible ? -1 : idx).Where(x => x > -1).ToArray();
253253
var nonSearchableColumns = columns.Select((x, idx) => x.Searchable ? -1 : idx).Where(x => x > -1).ToArray();
254254
var mRenderColumns = columns.Select((x, idx) => string.IsNullOrEmpty(x.MRenderFunction) ? new { x.MRenderFunction, Index = -1 } : new { x.MRenderFunction, Index = idx }).Where(x => x.Index > -1).ToArray();
255+
var CssClassColumns = columns.Select((x, idx) => string.IsNullOrEmpty(x.CssClass) ? new { x.CssClass, Index = -1 } : new { x.CssClass, Index = idx }).Where(x => x.Index > -1).ToArray();
255256

256257
var defs = new List<dynamic>();
257258

@@ -266,6 +267,11 @@ private static string convertColumnDefsToJson(IEnumerable<ColDef> columns)
266267
{
267268
defs.Add(new { mRender = "%" + mRenderColumn.MRenderFunction + "%", aTargets = new[] {mRenderColumn.Index} });
268269
}
270+
if (CssClassColumns.Any())
271+
foreach (var CssClassColumn in CssClassColumns)
272+
{
273+
defs.Add(new { className = CssClassColumn.CssClass, aTargets = new[] { CssClassColumn.Index } });
274+
}
269275

270276
if (defs.Count > 0)
271277
return new JavaScriptSerializer().Serialize(defs).Replace("\"%", "").Replace("%\"", "");

Mvc.JQuery.Datatables/DataTablesHelper.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ public static ColDef[] ColDefs<TResult>()
4949
Visible = pi.Item2.Visible,
5050
Searchable = pi.Item2.Searchable,
5151
SortDirection = pi.Item2.SortDirection,
52-
MRenderFunction = pi.Item2.MRenderFunction
52+
MRenderFunction = pi.Item2.MRenderFunction,
53+
CssClass = pi.Item2.CssClass,
54+
CssClassHeader = pi.Item2.CssClassHeader
5355
});
5456
}
5557
return columnList.ToArray();

Mvc.JQuery.Datatables/DataTablesTypeInfo.cs

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public DataTablesAttribute()
7373
public Type DisplayNameResourceType { get; set; }
7474
public SortDirection SortDirection { get; set; }
7575
public string MRenderFunction { get; set; }
76+
public String CssClass { get; set; }
77+
public String CssClassHeader { get; set; }
7678

7779
public bool Visible { get; set; }
7880
}

0 commit comments

Comments
 (0)