我一直试图在过去的3小时内解决这个问题,我决定从操纵DOM转而使用服务器端ajax,因为我正在使用10,000多行。
我已经设法获取表格中的数据,但一切看起来都不错,除了我不断收到警报"请求的未知参数' 0'对于第0行,第0列和第34行;我无法弄清楚为什么!!
我搜索并搜索但没有发现任何有用的东西。
有人可以帮忙吗?
PS:我尝试使用
"columns": [
{ "data": 'UserName' }
]
但这根本没有帮助......
$('#myTable').DataTable( {
stateSave: false,
"processing": true,
"serverSide": true,
"ajax": "include/ssp.php",
searchHighlight: true,
"pageLength": 25,
"lengthMenu": [[10, 25, 50, 100, -1], ["10 lignes", "25 lignes", "50 lignes", "100 lignes", "Tout"]],
"scrollY": "70vh",
"pagingType": "simple",
"scrollCollapse": true,
"paging": true,
"bSortClasses": false,
dom: '<"row"<"col-lg-6 col-md-6 col-sm-6 col-xs-12"B><"col-lg-6 col-md-6 col-sm-6 col-xs-12"p>><"row"<"col-lg-6 col-md-6 col-sm-6 col-xs-12"<"fsearch">><"col-lg-6 col-md-6 col-sm-6 col-xs-12"f>>rti',
"footerCallback": function ( row, data, start, end, display ) {
var api = this.api(), data;
var intVal = function ( i ) {
return typeof i === 'string' ?
i.replace(/[\$,]/g, '')*1 :
typeof i === 'number' ?
i : 0;
};
stockAll = api.column( 4 ).data().reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
$( api.column( 4 ).footer() ).html(stockAll);
cfAll = api.column( 8 ).data().reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
$( api.column( 8 ).footer() ).html(cfAll);
},
drawCallback: function(settings){
var api = this.api();
$('td:nth-child(9)', api.table().container()).each(function () {
$(this).attr('title', api.cell($(this).parent('tr'), 9).data());
});
$('td:nth-child(9)', api.table().container()).tooltip({
container: 'body'
});
$('td:nth-child(5)', api.table().container()).each(function () {
var stock = parseFloat(api.cell($(this).parent('tr'), 4).data());
var resa = parseFloat(api.cell($(this).parent('tr'), 10).data());
var total = stock-resa;
if(resa > 0){
$(this).attr('title', 'Stock réel: '+total);
}
});
$('td:nth-child(5)', api.table().container()).tooltip({
container: 'body'
});
},
buttons: [
{
extend: 'collection',
text: 'Réglage',
className: "btn-primary",
autoClose: true,
buttons: [
{
extend: 'collection',
text: 'Paramètres',
buttons: [
{
extend: 'pageLength',
text: 'Ligne par page'
},
{
text: 'Cadre d’image',
action: function displayImageFrame() {
var table = $('#myTable').DataTable();
$("#right").toggle();
$("#left").toggleClass("col-lg-7 col-lg-12");
$("#left").toggleClass("col-md-7 col-md-12");
table.draw();
}
},
{
extend: 'collection',
text: 'Colonnes',
buttons: [
{
extend: 'colvis',
columns: [2,3,4,5,6,7,8,9,10,11]
},
{
extend: 'colvisGroup',
text: 'Groupe - Prix',
show: [ 0,1,2,5,6,7,11 ],
hide: [ 3,4,8,9,10 ]
},
{
extend: 'colvisGroup',
text: 'Groupe - Stock',
show: [ 0,1,2,4,8,9,10 ],
hide: [ 3,5,6,7,11 ]
},
{
extend: 'colvisRestore',
text: 'Colonnes par défaut'
},
]
},
{
text: 'Plein écran',
action: function toggleFullScreen() {
if (!document.fullscreenElement && // alternative standard method
!document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement ) { // current working methods
if (document.documentElement.requestFullscreen) {
document.documentElement.requestFullscreen();
} else if (document.documentElement.msRequestFullscreen) {
document.documentElement.msRequestFullscreen();
} else if (document.documentElement.mozRequestFullScreen) {
document.documentElement.mozRequestFullScreen();
} else if (document.documentElement.webkitRequestFullscreen) {
document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
}
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
}
}
}
]
},
{
extend: 'collection',
text: '(Dé)Sélectionner',
buttons: [
{
extend: 'selectAll',
text: 'Sélectionner tout'
},
{
text: 'Sélectionner filtré',
action: function SelectFiltered(e) {
e.preventDefault();
var table = $("#myTable").DataTable();
table.rows({filter:"applied"}).select();
}
},
{
extend: 'selectNone',
text: 'Tout déselectionner'
}
]
},
{
extend: 'collection',
text: 'Export',
buttons: [
{
extend: 'copyHtml5',
text: 'Copier tout',
exportOptions: {
columns: [2,3,4,5,6,7,8,9,10,11]
}
},
{
extend: 'copyHtml5',
text: 'Copier sélection',
exportOptions: {
columns: [2,3,4,5,6,7,8,9,10,11],
modifier: {
selected: true
}
}
},
{
extend: 'csvHtml5',
text: 'CSV sélection',
title: 'Order',
filename: 'Order',
fieldSeparator: ';',
extension: '.csv',
exportOptions: {
columns: [2,3,4,5,6,7,8,9,10,11],
modifier: {
selected: true
}
}
},
{
extend: 'excelHtml5',
text: 'Excel sélection',
title: 'Order',
exportOptions: {
columns: [2,3,4,5,6,7,8,9,10,11],
modifier: {
selected: true
}
}
},
{
extend: 'print',
text: 'Imprimer tout',
exportOptions: {
columns: ':visible'
}
},
{
extend: 'print',
text: 'Imprimer sélection',
exportOptions: {
columns: [2,3,4,5,6,7,8,9,10,11],
modifier: {
selected: true
}
}
},
{
extend: 'pdfHtml5',
text: 'PDF',
title: 'Order',
exportOptions: {
columns: ':visible'
}
},
{
extend: 'excelHtml5',
text: 'Enregistrer la sélection',
title: 'Selection',
exportOptions: {
columns: [2],
modifier: {
selected: true
}
}
}
]
}
]
}
],
"columnDefs": [
{
"className": 'control',
"orderable": false,
"targets": 0
},
{
"orderable": false,
"className": 'select-checkbox',
"targets": 1
},
{
"data": 'product_reference',
"targets" : 2
},
{
"data": 'product_brand',
"targets" : 3
},
{
"data": 'stock_qty',
"createdCell": function (td, cellData, rowData, row, col) {
if ( cellData < 1 ) {
$(td).css("background-color", "#FF6961");
}
},
"targets" : 4
},
{
"defaultContent": "-",
"targets": 5
},
{
"data": 'product_tb1',"createdCell": function (td, cellData, rowData, row, col) {
if ( (cellData == 0) || (cellData == "#N/A") || (cellData == 999)) {
$(td).css("background-color", "#FDFD96");
}
},
"targets": 6
},
{
"data": 'product_rrp',
"createdCell": function (td, cellData, rowData, row, col) {
if ( (cellData < 1) || (cellData == "#N/A") ) {
$(td).css("background-color", "#FDFD96");
}
},
"targets": 7
},
{
"data": 'product_cf',
"createdCell": function (td, cellData, rowData, row, col) {
if ( cellData > 1 ) {
$(td).css("background-color", "#BDECB6");
}
},
"targets": 8
},
{
"data": 'product_cf_date',
"targets": 9
},
{
"defaultContent": "-",
"targets": 10
},
{
"data": 'product_pmp',
"createdCell": function (td, cellData, rowData, row, col) {
if ( (cellData < 1) || (cellData == "#N/A") ) {
$(td).css("background-color", "#FDFD96");
}
},
"targets": 11
},
{
"visible": false,
"targets": [9,10,11]
}
],
"order": [[ 2, 'asc' ]],
select: {
style: 'multi+shift',
selector: 'tr>td:nth-child(2)'
},
"language": {
"sProcessing": "Traitement en cours...",
"sSearch": "",//"Rechercher :",
"sLengthMenu": "Afficher _MENU_ lignes",
"sInfo": "_START_ à _END_ sur _TOTAL_ éléments",
"sInfoEmpty": "Affichage de l'élément 0 à 0 sur 0 élément",
"sInfoFiltered": "(filtré de _MAX_ éléments au total)",
"sInfoPostFix": "",
"sLoadingRecords": "Chargement en cours...",
"sZeroRecords": "Aucun élément à afficher",
"sEmptyTable": "Aucune donnée disponible dans le tableau",
"oPaginate": {
"sFirst": "Premier",
"sPrevious": "Précédent",
"sNext": "Suivant",
"sLast": "Dernier"
},
"oAria": {
"sSortAscending": ": activer pour trier la colonne par ordre croissant",
"sSortDescending": ": activer pour trier la colonne par ordre décroissant"
},
buttons: {
colvis: "Colonnes visibles",
selectAll: "Sélectionner tout",
selectNone: "Tout déselectionner"
},
select: {
rows: {
_: " (%d lignes sélectionné)",
//0: " (Cliquez sur une ligne pour la sélectionner)",
0: "",
1: " (1 ligne sélectionné)"
}
}
},
colReorder: true,
keys: {
columns: ':nth-child(3)',
focus: ':eq(2)',
blurable: true
},
responsive: true,
initComplete: function () {
this.api().columns(3).every( function () {
var column = this;
var select = $('<select id="filter_brand" class="form-control input-sm"><option value="">------</option></select>')
.appendTo( $(column.footer()).empty() )
.on( 'change', function () {
$(this).blur();
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search( val ? '^'+val+'$' : '', true, false )
.draw();
} );
column.data().unique().sort().each( function ( d, j ) {
select.append( '<option value="'+d+'">'+d+'</option>' )
} );
} );
}
} );
答案 0 :(得分:0)
尝试在此处添加逗号:
"visible": false,
"targets": [9,10,11]
下面:
},
然后继续
],
"order": [[ 2, 'asc' ]],
select: {
style: 'multi+shift',
这让我有一次以类似的方式吸引我。