Ò»¡¢±³¾°
¡¡¡¡ÏîÄ¿ÀïÃæÓиö±í¸ñÄ£¿é£¬ÒªÌṩ±í¸ñµÄ¹ýÂË¡¢ÅÅÐò¡¢·ÖÒ³¡¢±à¼¡¢´òÓ¡µÈ¹¦ÄÜ£»ÔÚÍøÉÏÕÒÁ˲»Éٿؼþ£¬ÆäÖÐSpreadJSÕâ¸ö´¿Ç°¶Ë±í¸ñ¿Ø¼þ»ù±¾ÉÏ¿ÉÒÔʵÏÖexcelµÄËùÓй¦ÄÜ£¬ÍêÃÀÂú×ãÒªÇ󣬲»¹ýÊÇÊÕ·ÑÁ˵ģ¬Ö»ÄÜ×÷°Õ£¬ºóÀ´·¢ÏÖDatatablesÆäʵҲ²»´í£¬À©Õ¹¹¦Äܶ࣬¶øÇÒ×Ô¼ºÒ²¿ÉÒÔÁíÍâÔÚдһЩ¹¦ÄܽøÈ¥¡£DatatablesµÄÎĵµ¹ÙÍøÉÏÃæÓУ¬¸÷ÖÖÓ÷¨µÄÀý×ÓÒ²ºÜ¶à£º
¡¡¡¡×Ðϸ²éÕÒ×Ü»áÓÐÄãÏëÒªµÄ¡£
¶þ¡¢»ù´¡Ó÷¨
¡¡¡¡ÒýÈëjquery¡¢dataTablesµÄjsÓëcss£¬È»ºó³õʼ»¯Ò»¸ötable±êÇ©¾Í¿ÉÒÔÁË¡£
$(document).ready(function() { $().DataTable(); });
¡¡¡¡ÖÁÓÚ±í¸ñÖеÄÊý¾ÝÓжàÖÖ·½Ê½Ìí¼Ó½øÈ¥£¬±ÈÈç<table>±êÇ©ÀïÃæ±¾À´¾ÍÒѾ°üº¬ÁËËùÓеÄÊý¾Ý£¬»òÕßͨ¹ýjs¶¨ÒåµÄÊý¾ÝÒÔ¼°Í¨¹ýajax´Óºǫ́»ñÈ¡µÄÊý¾Ý£º
Column 1Column 2Column 3Column 4]]; ).DataTable( 17 data:data );
¡¡¡¡ÕâЩ¶¼±È½Ï¼òµ¥£¬²»¹ýÌí¼ÓÀ©Õ¹¹¦ÄÜ»òÕß½áºÏbootstrapÑùʽ£¬»áÓÐÒ»µãµãÂé·³£¬²»¹ý¶àÊÔÒ»ÏÂÎĵµ£¬Ò²ºÜ¼òµ¥ÁË£¬ÕâÀïÖ÷ÒªÊÇ°ÑʵÏÖ±êÌâËù˵µÄ¹¦ÄÜ£¬ÐèÒªÒýÈëµÄÎļþÁгöÀ´Ò»Ï£¬±ÜÃâ²»±ØÒªµÄÂé·³
¡¡¡¡ÕâÀïÃæÓÐЩÎļþÊÇdataTables°üÀïÃæûÓеÄÐèÒªµ¥¶ÀÈ¥ÏÂÔØ£¬pdfmakeºÍJSZip¡£
¡¡¡¡°´Å¥µÄ³õʼ»¯£º
var table = $('#example').DataTable({
//ajax: 'server/data',
data: data,
buttons: [{
extend: 'copy',
className: 'btn btn-default', //Ìí¼Ó¶îÍâµÄÑùʽ
text:'<span></span>' //×ÖÌåͼ±ê
}, {
extend: 'csv',
className: 'btn btn-default',
text:'<span></span>'
}, {
extend: 'excel',
className: 'btn btn-default',
text:'<span></span>'
}, {
extend: 'pdf',
className: 'btn btn-default',
text:'<span></span>'
}, {
extend: 'print',
className: 'btn btn-default',
text:'<span></span>'
}],
});
table.buttons().container().appendTo($('.buttons')); //°Ñ°´Å¥Ìí¼Óµ½Ö¸¶¨µÄÈÝÆ÷ÀïÃæ
¡¡¡¡ÁíÍâÓÐÒ»µã¾ÍÊDZí¸ñÖеÄÊý¾ÝÊDz»¿É±à¼µÄ£¬ÎÒ¾ÍдÁËÒ»¸öµ¥»÷ij¸öµ¥Ôª¸ñ£¬½«Æä±ä³ÉÒ»¸öÊäÈë¿ò£¬Íâ±í¿´À´Ö»ÊǶàÁËÒ»¸ö¹â±ê£¬ÀàËÆexcelµÄ±à¼Ð§¹û£¬ÊäÈë¿ò»ñµÃ½¹µã£¬¹â±êÔÚÎÄ×ÖµÄβ²¿´úÂë·îÉÏ
/** * ÊäÈë¿ò»ñµÃ½¹µãºó£¬¹â±êÔÚÎÄ×Ö×îºóÃæ * @param {[type]} position [description] * @return {[type]} [description] */ $.fn.setCursorPosition = function(position) { if (this.lengh == 0) return this; return $(this).setSelection(position, position); } $.fn.setSelection = function(selectionStart, selectionEnd) { if (this.lengh == 0) return this; input = this[0]; if (input.createTextRange) { var range = input.createTextRange(); range.collapse(true); range.moveEnd('character', selectionEnd); range.moveStart('character', selectionStart); range.select(); } else if (input.setSelectionRange) { input.focus(); input.setSelectionRange(selectionStart, selectionEnd); } return this; } $.fn.focusEnd = function() { this.setCursorPosition(this.val().length); }
¡¡¡¡Ö±½Óµ÷ÓþͿÉÒÔÁË£º$('input').focusEnd()£»ÁíÍ⸽ÉϽçÃæͼƬ£º
¡¡¡¡
¡¡