I have this dilemma with Datatable. I load the data in the datatable and initialize it 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 initializing 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 get updated data via Ajax, I can't hide it and it shows up 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%");
}
You could add this parameter
searching: false
to disable search andpaging: false
for paging, to the configuration object ofDataTable
.For versions older than 1.10
For versions less than 1.10