Datatable Format after Reloading Data

0

I have this dilemma with Datatable. I load the data in the datatable and initialize perfectly with this code:

$(document).ready(function () {

        $('.table').DataTable({
            sScrollX: false,
            dom: 'Bfrtip',
            //Elijo que tamanio tendran las columnas
            aoColumnDefs: [
                { sWidth: "5%", "aTargets": [0] },
                { sWidth: "10%", "aTargets": [1] },
                { sWidth: "65%", "aTargets": [2] },
                { sWidth: "10%", "aTargets": [3] },
                { sWidth: "5%", "aTargets": [4] },
                { sWidth: "5%", "aTargets": [5] }
            ], columnDefs: [
                { responsivePriority: 5, targets: -1 },
                { responsivePriority: 4, targets: 3 },
                { responsivePriority: 3, targets: 2 },
                { responsivePriority: 2, targets: 1 },
                { responsivePriority: 1, targets: 0 }

            ],
            pageLength: 10,
            lengthChange: true,
            paging: true,
            responsive: false,

            language: {
                "lengthMenu": "Mostrando _MENU_ Datos por página.",
                "zeroRecords": "No hay existen registros para los filtros seleccionados.",
                "info": "Página _PAGE_ de _PAGES_",
                "infoEmpty": "No hay datos registrados",
                "infoFiltered": "(Filtrado de _MAX_ datos totales.)",
                "paginate": {
                    "first": "Primera",
                    "last": "Ultima",
                    "previous": "<",
                    "next": ">"
                },

            }

        });
        $("#gridTable_filter input").attr("id", "inputFiltro");
        $('#gridTable_filter').css("display", "none");
        $('.dataTables_info').css("margin-left", "2%");
    });

But I hide the Search textbox and the Pagination textbox when I initialize it. Something that can be seen at the end.

  $("#gridTable_filter input").attr("id", "inputFiltro");
        $('#gridTable_filter').css("display", "none");
        $('.dataTables_info').css("margin-left", "2%");

But when I do a search and I bring updated data through Ajax, I can not hide and appear again.

  // Do a New Search
    function DoSearch() {
        var _Name = $('#txtName_Filter').val();
        var _TypeCfe = $('#txtTypeCfe_Filter').val();
        var _Active = null;




        if (_Name == "") { _Name = null; }
        if (_TypeCfe == 0) { _TypeCfe = null; }
        if ($("#chkActive_Filter").is(":checked")) { _Active = true; }


        var _data = {
            Name: _Name,
            CfeType: _TypeCfe,
            Active: _Active
        };
        $.ajax(
        {
            url: '@Url.Action("RefreshDocumentModelsList", "SystemSettings")'
            , type: "GET"
            , data: _data
            , contentType: 'application/json'
        })
        .done(function (result) {
            $("#divList").html(result);
            // #region DataTable

            $('.table').DataTable({
            });

            // #endregion
        })
        .fail(function (e) {
            swal({
                title: 'Error',
                text: e.Message,
                type: 'warning'
            });
        });
        $("#gridTable_filter input").attr("id", "inputFiltro");
        $('#gridTable_filter').css("display", "none");
        $('.dataTables_info').css("margin-left", "2%");
    }

    
asked by Maximiliano Cesán 12.02.2018 в 16:48
source

1 answer

1

You could add this parameter searching: false to enable the search and paging: false for the page, to the configuration object of DataTable .

For versions greater than 1.10

$('table').dataTable({searching: false, paging: false});

For versions under 1.10

$('table').dataTable({bFilter: false, bInfo: false});
    
answered by 12.02.2018 / 16:50
source