PLUGIN_D7TABLE2EXCEL

/*
* d7table2xls — plugin based on jQuery for platform SCAD7
*
* Copyright (c) 2019 Dobrynin P. Yu.
*
* Version: 1.0.0
*
* home page link:
* http://platforma.scad7.ru
*
* Добавить виджет экспорта таблицы в Excel
* $(‘#table’).d7table2xls({dt_to: ‘dt_to’});
* $(‘#table’).d7table2xls();
*
* Уничтожить виджет
* $(‘#table’).d7table2xls(‘destroy’);
*/

(function( $ ){
var methods = {
init : function( options ) {
var settings = $.extend({
exclude: ‘.grp_ord’
, name: »
, sheetName: »
, filename: »
, fileext: ‘.xls’
, preserveColors: false
, exclude_img: true
, exclude_links: true
, exclude_inputs: true
}, options);
return this.each(function(index){
var $this = $(this), data = $this.data(‘d7table2xls’);

if ( ! data) {
$(this).data(‘d7table2xls’, {
target : $this
, id : $this.attr(‘id’)
, ctrlid : $this.attr(‘id’) + ‘_XLS’
, exclude : settings.exclude
, name : settings.name
, sheetName : settings.sheetName
, filename : settings.filename
, fileext : settings.fileext
, preserveColors : settings.preserveColors
, exclude_img : settings.exclude_img
, exclude_links : settings.exclude_links
, exclude_inputs : settings.exclude_inputs
});
}
data = $this.data(‘d7table2xls’);
// — тело виджета ——————————
$.getScript(«js/table2excel/dist/jquery.table2excel.min.js», function( data_, textStatus, jqxhr ) {
if ( textStatus === ‘success’ ) {
$(‘#’+data.id).before(‘‘);
$(‘#’+data.ctrlid).on(‘click’, function(){
$(‘#’+data.id).table2excel({
exclude: data.exclude
, name: data.name
, sheetName: data.sheetName
, filename: data.filename
, preserveColors: data.preserveColors
, exclude_img: data.exclude_img
, exclude_links: data.exclude_links
, exclude_inputs: data.exclude_inputs
});
});
};
});
// ———————————————
}); //return
}//init
, destroy : function() {
return this.each(function(){
var $this = $(this), data = $this.data(‘d7table2xls’);
$(window).unbind(‘.d7table2xls’);
$this.removeData(‘d7table2xls’);
$(‘#’ + data.ctrlid).remove();
}); //return
}//destroy
, run : function run() {
return this.each(function() {
return this;
}); //return
}//run
};

$.fn.d7table2xls= function( method ) {
if ( methods[method] ) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if ( typeof method === ‘object’ || ! method) {
return methods.init.apply( this, arguments );
} else {
$.error( ‘Метод с именем ‘ + method + ‘ не существует для jQuery.d7table2xls’ );
}
};
})( jQuery )