|
1 |
| -/*! |
| 1 | +/*! |
2 | 2 | * jQuery DataTables Checkboxes (https://www.gyrocode.com/projects/jquery-datatables-checkboxes/)
|
3 | 3 | * Checkboxes extension for jQuery DataTables
|
4 | 4 | *
|
|
362 | 362 | }
|
363 | 363 |
|
364 | 364 | // Handle Ajax request completion event
|
365 |
| - // NOTE: Needed to update table state |
| 365 | + // NOTE: Needed to update table state |
366 | 366 | // if table is reloaded via ajax.reload() API method
|
367 | 367 | $(dt.table().node()).on('xhr.dt.dtCheckboxes', function ( e, settings , json, xhr ) {
|
368 | 368 | self.onDataTablesXhr(e. settings, json, xhr);
|
|
474 | 474 |
|
475 | 475 | $.each(self.s.columns, function(index, colIdx){
|
476 | 476 | self.updateSelectAll(colIdx);
|
477 |
| - }); |
| 477 | + }); |
478 | 478 | },
|
479 | 479 |
|
480 | 480 | // Handles DataTables Ajax request completion event
|
|
583 | 583 | self.updateStateCheckboxes({ page: 'all', search: 'none' });
|
584 | 584 |
|
585 | 585 | // If FixedColumns extension is enabled
|
586 |
| - if(ctx._oFixedColumns){ |
| 586 | + if(ctx._oFixedColumns){ |
587 | 587 | // Use delay to let FixedColumns construct the header
|
588 | 588 | // before we update the "Select all" checkbox
|
589 | 589 | setTimeout(function(){
|
|
652 | 652 | var cell = dt.cell(cellSelector);
|
653 | 653 | var cellIdx = cell.index();
|
654 | 654 | var colIdx = cellIdx.column;
|
| 655 | + var rowIdx = cellIdx.row; |
655 | 656 |
|
656 | 657 | // If row selection is not enabled
|
657 | 658 | // NOTE: if row selection is enabled, checkbox selection/deselection
|
|
663 | 664 | e.stopPropagation();
|
664 | 665 |
|
665 | 666 | } else {
|
666 |
| - // WORKAROUND: |
667 |
| - // Select extension may keep the row selected |
668 |
| - // when checkbox is unchecked with SHIFT key. |
669 |
| - // |
670 |
| - // We need to update the state of the checkbox AFTER handling |
671 |
| - // select/deselect event from Select extension. |
672 |
| - // |
673 |
| - // Call to setTimeout is needed to let select/deselect event handler |
674 |
| - // update the data first. |
675 |
| - setTimeout(function(){ |
676 |
| - // Get cell data |
677 |
| - var cellData = cell.data(); |
678 | 667 |
|
679 |
| - // Determine whether data is in the list |
680 |
| - var hasData = ( |
681 |
| - Object.prototype.hasOwnProperty.call(self.s.data, colIdx) |
682 |
| - && Object.prototype.hasOwnProperty.call(self.s.data[colIdx], cellData) |
683 |
| - ); |
| 668 | + // If Select extension is enabled |
| 669 | + if(ctx._select){ |
| 670 | + // If style is set to "os" |
| 671 | + if(ctx._select.style === 'os'){ |
684 | 672 |
|
685 |
| - // If state of the checkbox needs to be updated |
686 |
| - if(hasData !== ctrl.checked){ |
687 |
| - self.updateCheckbox(cell, colIdx, hasData); |
688 |
| - self.updateSelectAll(colIdx); |
| 673 | + // WORKAROUND: |
| 674 | + // See https://github.com/gyrocode/jquery-datatables-checkboxes/issues/128 |
| 675 | + |
| 676 | + // Prevent click event from propagating to parent |
| 677 | + e.stopPropagation(); |
| 678 | + |
| 679 | + // Select/deselect individual row |
| 680 | + cell.checkboxes.select(ctrl.checked); |
| 681 | + |
| 682 | + // Otherwise, if style is set to other than "os" |
| 683 | + } else { |
| 684 | + // WORKAROUND: |
| 685 | + // Select extension may keep the row selected |
| 686 | + // when checkbox is unchecked with SHIFT key. |
| 687 | + // |
| 688 | + // We need to update the state of the checkbox AFTER handling |
| 689 | + // select/deselect event from Select extension. |
| 690 | + // |
| 691 | + // Call to setTimeout is needed to let select/deselect event handler |
| 692 | + // update the data first. |
| 693 | + setTimeout(function(){ |
| 694 | + // Get cell data |
| 695 | + var cellData = cell.data(); |
| 696 | + |
| 697 | + // Determine whether data is in the list |
| 698 | + var hasData = ( |
| 699 | + Object.prototype.hasOwnProperty.call(self.s.data, colIdx) |
| 700 | + && Object.prototype.hasOwnProperty.call(self.s.data[colIdx], cellData) |
| 701 | + ); |
| 702 | + |
| 703 | + // If state of the checkbox needs to be updated |
| 704 | + if(hasData !== ctrl.checked){ |
| 705 | + self.updateCheckbox(cell, colIdx, hasData); |
| 706 | + self.updateSelectAll(colIdx); |
| 707 | + } |
| 708 | + }, 0); |
689 | 709 | }
|
690 |
| - }, 0); |
| 710 | + } |
691 | 711 | }
|
692 | 712 | },
|
693 | 713 |
|
|
827 | 847 | $checkboxesSelectAll.data('is-changed', false);
|
828 | 848 |
|
829 | 849 | $checkboxesSelectAll.prop({
|
830 |
| - // NOTE: If checkbox has indeterminate state, |
| 850 | + // NOTE: If checkbox has indeterminate state, |
831 | 851 | // "checked" property must be set to false.
|
832 | 852 | 'checked': isIndeterminate ? false : isSelected,
|
833 | 853 | 'indeterminate': isIndeterminate
|
|
0 commit comments