How to make the lazy loading of a datatable work?

2

I currently use a library to make my datatable, which gives me many options to configure my table and what I understand one of them is the recharge option by necessity, this means that I will load my data from the bd as I go moving in the table and which I understand is called lazy loading.

This is how I set up my table:

$('#MainContent_tabla').DataTable({
                columns: [
{ title: "Nombre" },
{ title: "Vehiculo" },
{ title: "Fecha de Lectura" },
{ title: "Fecha de Salida" },
{ title: "Id del Usuario" },
{ title: "Imagen" }
                ],
                "language": {
                "lengthMenu": "Mostrar _MENU_ Registros por pagina",
                "zeroRecords": "No hay ningun registro que coincida",
                "info": "Mostrando pagina _PAGE_ of _PAGES_",
                "infoEmpty": "No hay registros disponibles",
                "infoFiltered": "(filtered from _MAX_ total records)",
                "search": "Buscar Palabra:",
                "paginate": {
                    "previous": "Siguiente",
                    "next": "Anterior"
                },
                "processing": true,
                "serverSide": true,
                "ajax": "ConsultarEvidencia.aspx.cs",
                "deferLoading": 57
            }
            });

The last 4 lines are for the slow loading option. Within the class that is called in ajax there is only one method that is the following:

 public void btnOk_T_Onclick(object sender, EventArgs e)
    {
        DataTable data = new DataTable();
        HistoryBI historyBi=new HistoryBI();

        Inicio = dtInicio.Text;
        Fin = dtFin.Text;

        data = historyBi.ConsultarEvidencia(Inicio,Fin);


        //DirectoryInfo d = new DirectoryInfo(@"C:\Users\Ned-Design\Documents\projects\NederaV4\Administrators\Temp");//Assuming Test is your Folder
        //FileInfo[] Files = d.GetFiles("*.png"); //Getting Text files



        foreach (DataRow dtRow in data.Rows)
        {

            TableRow row = new TableRow();

            for (int i=0;i<6;i++)
            {
                TableCell cell1 = new TableCell();
                cell1.Text = dtRow[i].ToString();
                row.Cells.Add(cell1);
            }

            tabla.Rows.Add(row);

        }



    }
    
asked by David 21.05.2018 в 17:20
source

1 answer

0

Your problem is that the options of

    "processing": true,
    "serverSide": true,
    "ajax": "ConsultarEvidencia.aspx.cs",
    "deferLoading": 57

are within languages. if you take the options to another bracket more should work.

        "language": {
        "lengthMenu": "Mostrar _MENU_ Registros por pagina",
        "zeroRecords": "No hay ningun registro que coincida",
        "info": "Mostrando pagina _PAGE_ of _PAGES_",
        "infoEmpty": "No hay registros disponibles",
        "infoFiltered": "(filtered from _MAX_ total records)",
        "search": "Buscar Palabra:",
        "paginate": {
            "previous": "Siguiente",
            "next": "Anterior"
        },
    },
        "processing": true,
        "serverSide": true,
        "ajax": "ConsultarEvidencia.aspx.cs",
        "deferLoading": 57
    
answered by 26.05.2018 / 16:53
source