//jumpserver 自定义js 2015-01-29 //此函数用于checkbox的全选和反选 var checked=false; function check_all(form) { var checkboxes = document.getElementById(form); if (checked === false) { checked = true; } else { checked = false; } for (var i = 0; i < checkboxes.elements.length; i++) { if (checkboxes.elements[i].type == "checkbox") { checkboxes.elements[i].checked = checked; } } } function checkAll(id, name){ var checklist = document.getElementsByName(name); if(document.getElementById(id).checked) { for(var i=0;i{}}, ...], // uc_html: 'header button', // op_html: 'div.btn-group?' // } var ele = options.ele || $('.dataTable'); var columnDefs = [ { targets: 0, orderable: false, createdCell: function(td) { $(td).html(''); } }, {className: 'text-center', targets: '_all'} ]; columnDefs = options.columnDefs ? options.columnDefs.concat(columnDefs) : columnDefs; var table = ele.DataTable({ pageLength: options.pageLength || 15, dom: options.dom || '<"#uc.pull-left"><"html5buttons"B>flti<"row m-t"<"#op.col-md-6"><"col-md-6"p>>', language: { url: options.i18n_url || "/static/js/plugins/dataTables/i18n/zh-hans.json" }, order: options.order || [[ 1, 'asc' ]], buttons: options.buttons || [ {extend: 'excel', exportOptions: { modifier: { selected: true } } }, {extend: 'pdf', exportOptions: { modifier: { selected: true } } }, {extend: 'print', customize: function (win){ $(win.document.body).addClass('white-bg'); $(win.document.body).css('font-size', '10px'); $(win.document.body).find('table') .addClass('compact') .css('font-size', 'inherit'); } } ], columnDefs: columnDefs, select: options.select || {style: 'multi'}, ajax: { url: options.ajax_url , dataSrc: "" }, columns: options.columns || [], lengthMenu: [[15, 25, 50, -1], [15, 25, 50, "All"]] }); table.on('select', function(e, dt, type, indexes) { var $node = table[ type ]( indexes ).nodes().to$(); $node.find('input.ipt_check').prop('checked', true); }).on('deselect', function(e, dt, type, indexes) { var $node = table[ type ]( indexes ).nodes().to$(); $node.find('input.ipt_check').prop('checked', false); }).on('draw', function(){ $('#op').html(options.op_html || ''); $('#uc').html(options.uc_html || ''); }); $('.ipt_check_all').on('click', function() { if (!jumpserver.checked) { $(this).closest('table').find('.ipt_check').prop('checked', true); jumpserver.checked = true; table.rows().select(); } else { $(this).closest('table').find('.ipt_check').prop('checked', false); jumpserver.checked = false; table.rows().deselect(); } }); return table; };