Skip to content

Commit b197fb7

Browse files
committed
Do widths properly
1 parent 38c0b5f commit b197fb7

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

Mvc.JQuery.Datatables.Example/Controllers/HomeController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class UserView
6767
[DataTables(DisplayName = "E-Mail", Searchable = true)]
6868
public string Email { get; set; }
6969

70-
[DataTables( Sortable = false, Width = "150px")]
70+
[DataTables( Sortable = false, Width = "70px")]
7171
public bool IsAdmin { get; set; }
7272

7373
[DataTables(Visible = false)]

Mvc.JQuery.Datatables.Example/Views/Home/_ExampleTable.cshtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
vm.LengthMenu.RemoveAll(t => t.Item2 == 5);
4242
vm.PageLength = 25; //... and set a default
4343
vm.ColVis = true;
44-
vm.FixedLayout = true;
4544
if (Request.QueryString["lang"] == "de")
4645
{
4746
//vm.Language = "{ 'sUrl': '" + Url.Content("~/Content/jquery.dataTables.lang.de-DE.txt") + "' }";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<tr>
1212
@foreach (var column in Model.Columns)
1313
{
14-
<th @(Html.Raw(column.Width != null ? "style='width:" + column.Width + "'" : ""))>@column.DisplayName</th>
14+
<th >@column.DisplayName</th>
1515
}
1616
</tr>
1717
}

Mvc.JQuery.Datatables/DataTableConfigVm.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public string ColumnDefsString
5050
{
5151
get
5252
{
53-
return ConvertColumnDefsToJson(Columns);
53+
return ConvertColumnDefsToJson(Columns.ToArray());
5454
}
5555
}
5656
public bool ColumnFilter { get; set; }
@@ -227,13 +227,15 @@ private static string ConvertDictionaryToJsonBody(IDictionary<string, object> di
227227
return json.Substring(1, json.Length - 2);
228228
}
229229

230-
private static string ConvertColumnDefsToJson(IEnumerable<ColDef> columns)
230+
private static string ConvertColumnDefsToJson(ColDef[] columns)
231231
{
232232
var nonSortableColumns = columns.Select((x, idx) => x.Sortable ? -1 : idx).Where( x => x > -1).ToArray();
233233
var nonVisibleColumns = columns.Select((x, idx) => x.Visible ? -1 : idx).Where(x => x > -1).ToArray();
234234
var nonSearchableColumns = columns.Select((x, idx) => x.Searchable ? -1 : idx).Where(x => x > -1).ToArray();
235235
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();
236236
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();
237+
238+
237239

238240
var defs = new List<dynamic>();
239241

@@ -254,6 +256,15 @@ private static string ConvertColumnDefsToJson(IEnumerable<ColDef> columns)
254256
defs.Add(new { className = CssClassColumn.CssClass, aTargets = new[] { CssClassColumn.Index } });
255257
}
256258

259+
for(var i=0;i<columns.Length;i++)
260+
{
261+
if (columns[i].Width != null)
262+
{
263+
defs.Add(new { width = columns[i].Width, aTargets = new[] { i} });
264+
}
265+
}
266+
267+
257268
if (defs.Count > 0)
258269
return new JavaScriptSerializer().Serialize(defs).Replace("\"%", "").Replace("%\"", "");
259270

0 commit comments

Comments
 (0)