-
Notifications
You must be signed in to change notification settings - Fork 110
Add master checkbox to Grid #1921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mvorisek
merged 70 commits into
atk4:develop
from
mhuser:add-master-checkbox-to-grid--addSelection()
Nov 24, 2024
Merged
Changes from all commits
Commits
Show all changes
70 commits
Select commit
Hold shift + click to select a range
4794b95
add master checkbox in table header
mhuser df9f80c
ugly working mastercheckbox
mhuser cebaf59
Add indeterminate state to master checkbox
mhuser 472db65
Merge branch 'atk4:develop' into add-master-checkbox-to-grid--addSele…
mhuser 2542bfc
add behat test
mhuser 7fd9d4b
Merge branch 'add-master-checkbox-to-grid--addSelection()' of https:/…
mhuser 3574c18
Fix merge git mess
mhuser f72140d
Toast selection
mhuser ce62a0a
Behat with selection toast
mhuser 5ed0e7a
syntax
mhuser 6a837c6
make behat happy
mhuser 8ead2ab
syntax
mhuser 761c459
add selector for behat
mhuser eb5b5ee
account for grid id
mhuser 86be84d
revert selector
mhuser 5900356
use same class as crud menu behat
mhuser 52ad16e
strip end blanks
mhuser ed8c541
correct row index
mhuser e942c77
js syntax
mhuser e4fa197
reduce ipp
mhuser 1b18382
more js syntax
mhuser 31a0f25
const $checkbox
mhuser 404861f
fix EOL and text empty selection reliably
mhuser a1a1a7a
fix EOL
mhuser 80ac317
make it npm friendly
mhuser df582bd
npm run build
mhuser 337b5e9
npm build 2nd attempt
mhuser f413c40
is this missing ?
mhuser 58bfe12
enforce LF against mysterious CRLF
mhuser 98533cf
even '\r\n' moved to '\n'
mhuser ad89648
some more tweaks
mhuser 5cc92ab
even more \r\n
mhuser 6674fc5
one more
mhuser 9bc4968
git reset --hard on Linux and npm run build
mhuser 3d6dc3f
Merge branch 'atk4:develop' into add-master-checkbox-to-grid--addSele…
mhuser 2b3c2ca
Merge branch 'atk4:develop' into add-master-checkbox-to-grid--addSele…
mhuser 9e018e1
Merge branch 'develop'
mvorisek 3fdd93a
fix merge
mvorisek 5a18354
npm run build js
mhuser 7118430
Merge remote-tracking branch 'upstream/develop' into add-master-check…
mhuser 024b5f9
more npm build
mhuser 245d5dc
even more npm build
mhuser da216b7
make behat happy
mhuser 676f65d
Revert "make behat happy"
mhuser 082ab90
fix slow checkbox on page load
mhuser 8fb3949
checkout lf files and npm run build
mhuser 159cf9b
fix checkbox column witdth
mhuser 7166991
restore js/package-lock.json and js/package.json
mhuser 9536060
npm run build again
mhuser 2e244bb
fix class array
mhuser 4eb182b
Merge branch 'develop'
mvorisek fe7d4ad
fix CS
mvorisek 390cc22
Merge branch 'develop'
mvorisek 8c4cc48
Merge branch 'develop'
mvorisek d85362a
Merge branch 'develop'
mvorisek a00ecac
Merge branch 'develop'
mvorisek 2608a62
Merge branch 'develop'
mvorisek 9469d03
fix performance issue after PR 2146
mvorisek ea43c69
Merge branch 'develop'
mvorisek fec1793
Merge branch 'develop'
mvorisek 1b28c35
simplify/fix Behat
mvorisek ad4909d
Merge branch 'develop'
mvorisek 88a17b0
Merge branch 'develop'
mvorisek 40eafb6
improve cs
mvorisek f12a5a5
optimize
mvorisek 3de6a22
move Behat test to a separate file
mvorisek 7276e60
fix cs
mvorisek 7073b69
revert changes to a moved demo
mvorisek c63e073
test master checkbox state using Behat
mvorisek da9c9e9
fix cs
mvorisek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Atk4\Ui\Demos; | ||
|
||
use Atk4\Ui\App; | ||
use Atk4\Ui\Grid; | ||
use Atk4\Ui\Js\Jquery; | ||
use Atk4\Ui\Js\JsToast; | ||
|
||
/** @var App $app */ | ||
require_once __DIR__ . '/../init-app.php'; | ||
|
||
$model = new Country($app->db); | ||
$grid = Grid::addTo($app, ['ipp' => 5]); | ||
$grid->setModel($model); | ||
|
||
$grid->addSelection(); | ||
|
||
$grid->addBulkAction('Show selected', static function (Jquery $j, array $ids) use ($grid) { | ||
return new JsToast('Selected: ' . implode(', ', array_map(static fn ($id) => $grid->getApp()->uiPersistence->typecastSaveField($grid->model->getIdField(), $id), $ids)) . '#'); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import $ from 'external/jquery'; | ||
|
||
function recomputeMasterCheckbox($table) { | ||
const $masterCheckbox = $table.find('.master.checkbox'); | ||
const $childCheckbox = $table.find('.child.checkbox'); | ||
|
||
const checkedCount = $childCheckbox.filter('.checked').length; | ||
const allChecked = checkedCount === $childCheckbox.length; | ||
const allUnchecked = checkedCount === 0; | ||
|
||
if (allChecked) { | ||
$masterCheckbox.checkbox('set checked'); | ||
} else if (allUnchecked) { | ||
$masterCheckbox.checkbox('set unchecked'); | ||
} else { | ||
$masterCheckbox.checkbox('set indeterminate'); | ||
} | ||
} | ||
|
||
export default { | ||
/** | ||
* Simple helper for master and child checkboxes connection. | ||
*/ | ||
setupMasterCheckbox: function (tableSelector) { | ||
const $table = $(tableSelector); | ||
let skipRecomputeMasterCheckbox = false; | ||
|
||
$table.find('.master.checkbox').checkbox({ | ||
onChecked: function () { | ||
const $childCheckbox = $table.find('.child.checkbox'); | ||
|
||
skipRecomputeMasterCheckbox = true; | ||
try { | ||
$childCheckbox.checkbox('check'); | ||
} finally { | ||
skipRecomputeMasterCheckbox = false; | ||
} | ||
}, | ||
|
||
onUnchecked: function () { | ||
const $childCheckbox = $table.find('.child.checkbox'); | ||
|
||
skipRecomputeMasterCheckbox = true; | ||
try { | ||
$childCheckbox.checkbox('uncheck'); | ||
} finally { | ||
skipRecomputeMasterCheckbox = false; | ||
} | ||
}, | ||
}); | ||
|
||
$table.find('.child.checkbox').checkbox({ | ||
onChange: function () { | ||
if (skipRecomputeMasterCheckbox) { | ||
return; | ||
} | ||
|
||
recomputeMasterCheckbox($table); | ||
}, | ||
}); | ||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.