How to send an Id (DiagramaId) to the Datatable to filter the data
How to send an Id (DiagramaId) to the Datatable to filter the data
I apologize, but I don't know how to put a test case
$(document).ready(function () {
tableBase = $('#tableGridDetail').DataTable({
dom: "lfrtip", // DOM
filter: true, // Filtrado de datos
info: true, // Resultado de busquedas
processing: true, // Muestra/Oculta la leyenda procesando
scrollX: true, // Scroll Horizontal
select: true, // Permite seleccionar el renglon
ordering: true, // Activa el ordenamiento
autoWidth: true, // Apaga el ancho automatico
lengthMenu: [[10, 50, 100, 150, -1], [10, 50, 100, 150, "Todos"]],
responsivePriority: 1,
scroller: { "loadingIndicator": true },
serverSide: true,
deferRender: true,
responsivePriority: 1,
data: null,
// Here I call the controller, but I don't know how to send the DiagramId so that it only retrieves the records of that ID
// Aqui llamo al controlador, pero no se como mandar el DiagramaId para que me recupere solo los registros de ese ID
ajax: {
url: "/DiagramaDetail/LoadDataGrid/",
type: "POST",
datatype: "json",
},
});
});
There is no error message, I just don't know how to send the DiagramaId parameter, note, the detail table has 63 fields and can return up to 600 rows
I am designing a system with Net Core 5 MVC, I have to show a Master-Detail, I already have the Master view that contains a Datatable, I would like that when clicking on the ID field (DiagramaId), the view with the detail would be displayed , but I don't know how to call the Detail view.
// This is the controller LoadDataGrid
[HttpPost]
public IActionResult LoadDataGrid(int id)
{
var draw = Request.Form["draw"].FirstOrDefault();
var start = Request.Form["start"].FirstOrDefault();
var length = Request.Form["length"].FirstOrDefault();
var sortColumn = Request.Form["columns[" + Request.Form["order[0][column]"].FirstOrDefault() + "][name]"].FirstOrDefault();
var sortColumnDir = Request.Form["order[0][dir]"].FirstOrDefault();
var searchValue = Request.Form["search[value]"].FirstOrDefault().ToUpper();
pageSize = length != null ? Convert.ToInt32(length) : 0;
skip = start != null ? Convert.ToInt32(start) : 0;
recordsTotal = 0;
List<VDiagramaDetailModel> ListVDiagramaDetailModel = Singleton.Instance.EntityManager.GetEntities<VDiagramaDetailModel>($"Diagrama_Id = {id}");
ListVDiagramaDetailModel = (from d in ListVDiagramaDetailModel select d).ToList();
/* Si tenemos una cadena de busqueda */
if (searchValue != "")
ListVDiagramaDetailModel = ListVDiagramaDetailModel.Where(x => x.DiagramaDetailId.ToString().Contains(searchValue)).ToList();
recordsTotal = ListVDiagramaDetailModel.Count;
/* Reordenar segun lo solicitado en el Grid */
switch (sortColumn)
{
case "diagramaDetailId":
if (sortColumnDir == "asc")
ListVDiagramaDetailModel = ListVDiagramaDetailModel.OrderBy(x => x.DiagramaDetailId).Skip(skip).Take(pageSize).ToList();
else
ListVDiagramaDetailModel = ListVDiagramaDetailModel.OrderByDescending(x => x.DiagramaDetailId).Skip(skip).Take(pageSize).ToList();
break;
default:
break;
}
return Json(new { draw, recordsFiltered = recordsTotal, recordsTotal, data = ListVDiagramaDetailModel });
}
Thanks for the help
Answers
Do you mean something along these lines?
Allan
It is not the best solution, but it works and it will give me time to analyze.
In a static class, save the ID when entering the controller that shows the detail, then when the Datatable enters, since the ID is zero, I assign the one that I previously saved and that's it, everything works perfectly.
This's my static class
Here I save the ID (Controller to load the Detail with an ID)
Here I retrieve the ID (Controller to load the Datatable)
Tanks for all, gracias por la ayuda