Код: Выделить всё
function openModal() {
showLoader();
var tableId = '#tableId';
$(tableId).DataTable().destroy();
$(tableId).DataTable({
serverSide: true,
paging: moduleDataTables.standardOptions.paging,
processing: moduleDataTables.standardOptions.processing,
searching: false,
scrollY: moduleDataTables.standardOptions.scrollY,
scrollCollapse: true,
ordering: false,
scrollX: true,
responsive: moduleDataTables.standardOptions.responsive,
pagingType: moduleDataTables.standardOptions.pagingType,
pageLength: 5,
lengthMenu: moduleDataTables.standardOptions.lengthMenu,
dom: moduleDataTables.standardOptions.dom,
buttons: moduleDataTables.standardOptions.buttons.GridNoButtons,
select: {
style: 'multi',
selector: 'td:first-child',
rows: {
_: "You have selected %d rows",
0: "Click a row to select it",
1: "Only 1 row selected" }
},
language: moduleDataTables.standardOptions.language,
columnDefs: [
{
orderable: false,
className: 'select-checkbox',
targets: 0
}
],
ajax: {
url: $("#GetDataTableModal_URI").val(),
crossDomain: true,
cache: false,
type: "POST",
contentType: 'application/x-www-form-urlencoded; charset=utf-8',
headers: {
Accept: 'application/json; charset=utf-8' },
data: function (data) { return $('#formTab').serialize(); },
dataSrc: function (response) {
return response.data;
},
beforeSend: function (xhr, settings) {
var info = $(tableId).DataTable().page.info();
xhr.setRequestHeader("Page", info.page);
xhr.setRequestHeader("Length", info.length);
xhr.setRequestHeader("RecordsTotal", info.recordsTotal);
},
error: function (xhr, ajaxOptions, thrownError) {
hideLoader();
showError(false, xhr);
},
complete: function (response) {
moduleDataTables.helpers.RecalcTables($('#divTable'));
$('.buttons-select-none').removeClass('disabled');
},
},
columns: [
{
"render": function (data, type, row, meta) {
var renderedButton = '_';
return renderedButton;
}
},
{ data: 'DESCRIPTION', searchable: true, ordering: false }
]
})
}
Это cshtml:
Код: Выделить всё
Des
Код: Выделить всё
[HttpPost]
public ActionResult GetDataTableModal(UserVM model)
{
try
{
RequestDTO request = new RequestDTO()
{
Tenant = Session["TenantId"].ToString(),
Login = model.Login
};
request.PagingRequest = GestioneDataTable.GetPagingRequest(Request.Headers);
var result = sicurezzaSVC.ExecuteAction(s => s.ProcessingFunc(request));
var dataTableResponse = GestioneDataTable.GetDataTableResponse(result.List, result.PagingResponse);
return Content(JsonConvert.SerializeObject(new { dataTable = dataTableResponse }), "application/json");
}
catch
{
return Content(JsonConvert.SerializeObject("KO"));
}
}
Код: Выделить всё
public ResponseDTO ProcessingFunc(RequestDTO request)
{
ResponseDTO response = new ResponseDTO();
var DataList = rp1.GetQueryable().Where(w => w.LOGIN == request.Login && w.TENTANT_ID == request.Tenant).Select(s => s.COD);
var pageToken = pageFactory.Create(DataList.Count(), request.PagingRequest.CurrentPage, request.PagingRequest.ItemsPerPage);
response.PagingResponse = typeAdapterSvc.ProjectAs
(pageToken);
List list1 = new List();
foreach (var x in DataList)
{
var ret = new TempDTO();
ret.DESCRIPTION = X.DESCRIPTION;
list1.Add(ret);
}
response.List = list1;
return response;
}
Подробнее здесь: https://stackoverflow.com/questions/785 ... ength-when