导出按钮(print和excel)不在数据表中

时间:2017-04-12 06:47:03

标签: javascript jquery html ajax datatable

我有一个数据表,其中表格数据通过点击搜索按钮动态传递。数据将介于FromData和Todata之间。对于每个searcg按钮,单击我希望表格清除,以便新数据不会附加到旧数据和清楚我正在使用$('#yourTableId').dataTable().fnClearTable(); 但问题是由于这个" fbClearTable();"导出按钮(打印和excel)不会到来。



var inittable = function() {
    var finance = $('#financetbl');
    var ofinance = finance.dataTable({
                // Internationalisation. For more info refer to http://datatables.net/manual/i18n
                "language": {
                    "aria": {
                        "sortAscending": ": activate to sort column ascending",
                        "sortDescending": ": activate to sort column descending"
                    },
                    "emptyTable": "No data available in table",

                    "zeroRecords": "No matching records found"
                },
                buttons: [{
                   extend: 'print',
                   className: 'btn dark btn-outline'
               }, {
                   extend: 'excel',
                   className: 'btn yellow btn-outline '
               }],
                responsive: false,
                //"ordering": false, disable column ordering 
                //"paging": false, disable pagination
                colReorder: {
                reorderCallback: function () {
                    console.log( 'callback' );
                }
            },
				
				"order": [
                    [0, 'asc']
                ],
                "lengthMenu": [
                    [5, 10, 15, 20, -1],
                    [5, 10, 15, 20, "All"] // change per page values here
                ],
                // set the initial value
                "pageLength":10,
                 "dom": "<'row' <'col-md-12'B>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>", // horizobtal scrollable datatable
                // Uncomment below line("dom" parameter) to fix the dropdown overflow issue in the datatable cells. The default datatable layout
                // setup uses scrollable div(table-scrollable) with overflow:auto to enable vertical scroll(see: assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.js). 
                // So when dropdowns used the scrollable div should be removed. 
                //"dom": "<'row' <'col-md-12'T>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r>t<'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>",
            });
        }
&#13;
&#13;
&#13;

&#13;
&#13;
$('#paymentdetails').click(function(){
					if( $(".datepickerInputFROM").val() > $(".datepickerInputTO").val())
						{
						alertify.alert('From Date should not be greater than  To Date')
						return false;
						$(".datepickerInputFROM").val ="";
						}
					var getData = basePath +'AdminFinance/GetStudentPaymentsForDate/?FromDate='+$(".datepickerInputFROM").val() + '&ToDate='+$(".datepickerInputTO").val()
					  
					  if (($(".datepickerInputFROM").val() == "") && ($(".datepickerInputTO").val() == ""))
					  { 
                            alertify.alert('Please select dates to proceed.')
							return false;
					  } else if (($(".datepickerInputFROM").val() == "") || ($(".datepickerInputTO").val() == ""))
					  { 
                            alertify.alert('Please select dates to proceed.')
							return false;
					  }
				
                     
                   
				$.ajax({
                        url: getData 
                        , async: false
                        , success: function (response) {
                           //  alert(response[0]);
                            //$('#financetbl tbody').empty();
						 $("#financetbl").dataTable().fnClearTable();
							
                           // if (response.resultCourse != '' && response[0]!= 'null') {
						    if (response.length > 0) {
                             var tr;
                                 for (var i = 0; i < response.length; i++) {
                                 tr = '<tr>'
                                 tr += "<td>" + response[i].transactionDate+ "</td>";
                                 tr += "<td>" + response[i].applicationNumber+ "</td>";
                                 tr += "<td>" + response[i].applicantName+ "</td>"
                              
                                 tr += '</tr>'
                                $("#financetbl").dataTable().fnAddData($(tr));
								}
								
								inittable();
                               console.log(response)
							  
                            }
                            else {
								console.log(response)
                                alertify.alert("Error : No Payments Details Found");
								
								
								
                            }
                        }
                    });
				});
&#13;
&#13;
&#13;

每当我从代码按钮中删除$('#yourTableId').dataTable().fnClearTable();时,即包括$('#yourTableId').dataTable().fnClearTable(); buttons are coming.

之后

1 个答案:

答案 0 :(得分:0)

我按照这种方式处理这些问题:

$(&#39;#TABLEID&#39)。dataTable中()fnDestroy();

你可以尝试一下!