Try your search with a different keyword or use * as a wildcard.
@model DataTablesModel
@functions
{
string GetUrl(DataUrl dataUrl)
{
return !string.IsNullOrEmpty(dataUrl?.ActionName) && !string.IsNullOrEmpty(dataUrl.ControllerName)
? Url.Action(dataUrl.ActionName, dataUrl.ControllerName, dataUrl.RouteValues)
: !string.IsNullOrEmpty(dataUrl.Url)
? $"{(dataUrl.Url.StartsWith("~/", StringComparison.Ordinal) ? Url.Content(dataUrl.Url) : dataUrl.Url).TrimEnd('/')}" + (!dataUrl.TrimEnd ? "/" : "")
: string.Empty;
}
string ReplaceName(string str)
{
return str.Replace("-", "_");
}
}
@{
//the locale which MomentJS should use
var locale = CultureInfo.CurrentCulture.Name;
//Model name for js function names
var model_name = ReplaceName(Model.Name);
//dom
var buttonsPanel = "";
var infoPanel = "<'col-lg-4 col-xs-12'<'float-lg-right text-center'i>>";
if (Model.RefreshButton && !Model.IsChildTable)
{
buttonsPanel = "<'col-lg-1 col-xs-12'<'float-lg-right text-center data-tables-refresh'B>>";
infoPanel = "<'col-lg-3 col-xs-12'<'float-lg-right text-center'i>>";
}
var dom = "<'row'<'col-md-12't>>" +
"<'row margin-t-5'" +
"<'col-lg-5 col-xs-12'<'float-lg-left'p>>" +
"<'col-lg-3 col-xs-12'<'text-center'l>>" +
infoPanel +
buttonsPanel +
">";
if (!string.IsNullOrEmpty(Model.Dom))
{
dom = Model.Dom;
}
//check using MasterCheckBox
var isMasterCheckBoxUsed = Model.ColumnCollection.Any(x => x.IsMasterCheckBox);
}
@if (!string.IsNullOrEmpty(Model.HeaderCallback))
{
headerCallback: function (thead, data, start, end, display) {
return @(Model.HeaderCallback)(thead, data, start, end, display);
},
}
@if (!string.IsNullOrEmpty(Model.FooterCallback))
{
footerCallback: function (tfoot, data, start, end, display) {
return @(Model.FooterCallback)(tfoot, data, start, end, display);
},
}
@if (!string.IsNullOrEmpty(Model.DrawCallback))
{
drawCallback: function (settings) {
return @(Model.DrawCallback)(settings);
},
}
@if (Model.Processing)
{
processing: @Model.Processing.ToString().ToLowerInvariant(),
}
@if (Model.ServerSide)
{
serverSide: @Model.ServerSide.ToString().ToLowerInvariant(),
}
@if (!string.IsNullOrEmpty(Model.RowIdBasedOnField))
{
rowId: function (item) {
var rowId = '';
if (item.hasOwnProperty('@(Model.RowIdBasedOnField)'))
{
if(item.@(Model.RowIdBasedOnField)){
var val = item.@(Model.RowIdBasedOnField).replace(/[^a-zA-Z0-9]/g, '').toLowerCase();
rowId = 'row_' + val;
} else return;
}
return rowId;
},
}
@if (Model.Data != null)
{
data: @Html.Raw(Model.Data.ToString()),
}
else
{
ajax:
{
url: "@Html.Raw(GetUrl(Model.UrlRead))",
type: "POST",
dataType: "json",
dataSrc: "Data",
beforeSend: function() {
@if (isMasterCheckBoxUsed)
{
clearMasterCheckbox('#@Model.Name');
}
},
data: function(data) {
@if (Model.Filters != null)
{
foreach (var filter in Model.Filters)
{
if (filter.Type == typeof(string))
{
if (Model.IsChildTable && !string.IsNullOrEmpty(filter.ParentName))
{
data.@filter.Name = row.data().@filter.ParentName;
continue;
}
if (!string.IsNullOrEmpty(filter.ModelName))
{
data.@filter.Name = $('#@(filter.ModelName)_@filter.Name').val();
}
else
{
data.@filter.Name = $('#@filter.Name').val();
}
continue;
}
if (filter.Type == typeof(bool))
{
data.@filter.Name = $('#@filter.Name').is(':checked');
continue;
}
if (filter.Type == typeof(int))
{
if (int.TryParse(@filter.Value.ToString(), out int val))
{
data.@filter.Name = @val;
}
continue;
}
if (filter.Type == typeof(DateTime?))
{
data.@filter.Name = $('#@filter.Name').val();
continue;
}
}
}
addAntiForgeryToken(data);
return data;
}
},
}
scrollX: true,
info: @Model.Info.ToString().ToLowerInvariant(),
paging: @Model.Paging.ToString().ToLowerInvariant(),
pagingType: '@Model.PagingType',
language: @await Html.PartialAsync("_GridLocalization"),
pageLength: @Model.Length,
@if (!string.IsNullOrEmpty(Model.LengthMenu))
{
lengthMenu: [@Model.LengthMenu],
}
else
{
lengthChange: false,
}
ordering: @Model.Ordering.ToString().ToLowerInvariant(),
@if (Model.RefreshButton)
{
buttons: [{
name: 'refresh',
text: '',
action: function() {
@if (Model.ServerSide)
{
updateTable('#@Model.Name', @isMasterCheckBoxUsed.ToString().ToLowerInvariant());
}
else
{
updateTableSrc('#@Model.Name', @isMasterCheckBoxUsed.ToString().ToLowerInvariant());
}
}
}],
}
dom: '@JavaScriptEncoder.Default.Encode(dom)',
columns: [
@for (int i = 0; i < Model.ColumnCollection.Count; i++)
{
var column = Model.ColumnCollection[i];
{
@if (!string.IsNullOrEmpty(column.Title) && !column.IsMasterCheckBox)
{
title: '@JavaScriptEncoder.Default.Encode(column.Title)',
}
else
{
if (!string.IsNullOrEmpty(column.Title) && column.IsMasterCheckBox)
{
title: '',
}
else
{
if (string.IsNullOrEmpty(column.Title) && column.IsMasterCheckBox)
{
title: '',
}
}
}
width: '@column.Width',
visible: @column.Visible.ToString().ToLowerInvariant(),
searchable: @column.Searchable.ToString().ToLowerInvariant(),
@if (column.AutoWidth)
{
autoWidth: @column.AutoWidth.ToString().ToLowerInvariant(),
}
@if (!string.IsNullOrEmpty(column.ClassName))
{
className: '@column.ClassName',
}
@if ((Model.UrlUpdate != null) || (Model.ChildTable?.UrlUpdate != null))
{
createdCell: function (td, cellData, rowData, row, col) {
$(td).attr('data-columnname', '@column.Data');
},
}
@if (column.Encode && column.Render == null)
{
render: function (data, type, row, meta) {
return escapeHtml(data);
},
}
@switch (column.Render)
{
case RenderLink link:
render: function (data, type, row, meta) {
var textRenderer = $.fn.dataTable.render.text().display;
@if (!string.IsNullOrEmpty(link.Title))
{
return '@JavaScriptEncoder.Default.Encode(link.Title)';
}
else
{
return '' + textRenderer(data) + '';
}
},
break;
case RenderDate date:
render: function (data, type, row, meta) {
return (data) ? moment(data).locale('@locale').format('@date.Format') : null;
},
break;
case RenderButtonRemove button:
render: function (data, type, row, meta) {
return '@button.Title';
},
break;
case RenderButtonsInlineEdit button:
render: function (data, type, row, meta) {
var origData = data;
var modData = data;
if (typeof data == 'string') {
modData = data.replace(/[.*+?^${}()|[\]\\]/g, "_");
}
return '@T("Admin.Common.Edit")' +
' ' +
' ';
},
break;
case RenderButtonEdit buttonEdit:
render: function (data, type, row, meta) {
return '@T("Admin.Common.Edit").Text';
},
break;
case RenderButtonView buttonView:
render: function (data, type, row, meta) {
return '@T("Admin.Common.View").Text';
},
break;
case RenderButtonCustom buttonCustom:
if (!string.IsNullOrEmpty(buttonCustom.Url))
{
render: function (data, type, row, meta) {
return '@JavaScriptEncoder.Default.Encode(buttonCustom.Title)';
},
}
if (!string.IsNullOrEmpty(buttonCustom.OnClickFunctionName))
{
render: function (data, type, row, meta) {
return '@JavaScriptEncoder.Default.Encode(buttonCustom.Title)';
},
}
break;
case RenderPicture picture:
var widthAttr = string.Empty;
render: function (data, type, row, meta) {
@if (picture.Width > 0)
{
widthAttr = "width=" + picture.Width;
}
@if (!string.IsNullOrEmpty(picture.Src))
{
return '';
}
else
{
return '';
}
},
break;
case RenderCheckBox checkBox:
render: function (data, type, row, meta) {
return (data === true)
? ''
: '';
},
break;
case RenderBoolean renderBoolean:
render: function (data, type, row) {
return data
? ''
: '';
},
break;
case RenderCustom custom:
render: function (data, type, row, meta) {
return @(custom.FunctionName)(data, type, row, meta);
},
break;
case RenderChildCaret caret:
render: function (data, type, row, meta) {
return '';
},
break;
}
data: '@column.Data'
}
@if (i != Model.ColumnCollection.Count - 1) {, }
}
]