question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a "select all" option for `addSelectedRows` plugin

See original GitHub issue

This is probably my favourite Svelte libraries, it’s so useful and versatile! Thank you so much for making this.

I do have one small gripe, which is that there isn’t a “select all” option for the addSelectedRows plugin. This can be hacked in like so:

// on init
let tableColumns = [];
    let selectAll = writable(false);
    if (selectable) {
        tableColumns.push(table.display({
			id: 'selected',
			header: () => createRender(Checkbox, { // renders the "select all"
                isSelected: selectAll
			}),
			cell: ({ row }, { pluginStates }) => {
                const { isSelected } = pluginStates.select.getRowState(row);
                return createRender(Checkbox, {
                    isSelected
				});
			},
			plugins: {
                sort: {
                    disable: true
				}
			}
		}));
	}
// ... continue initialising columns

and then subscribing to the newly created selectAll to cascade the changes to all other checkboxes:

const { selectedDataIds } = pluginStates.select;

    if (selectable) {
        selectAll.subscribe(val => {
            if (!val) selectedDataIds.clear();
            else {
                let rows = $pageRows;
                let newSelected = {};
                for (const row of rows) {
                    newSelected[row.id] = true;
                }

                $selectedDataIds = { ...newSelected };
            }
        });
	}

This works fine, but could run in to issues when trying to do things the other way around - ie. trying to select the “select all” option when all rows are selected. You could probably do something like:

selectedDataIds.subscribe(val => {
    if (val.length !== $pageRows.length) return;

    let newValue = true;
    for (const rowVal of val) {
        if (!rowVal) {
            newValue = false;
            break; // exit early
        }
    }

    $selectAll = newValue;
});

But you may run in to issues w/ constantly cascading changes between the 2 subscribe functions.

It’d be nice if there was a sane default for a select all option, especially if it were performant - I’m not too worried about the performance of the library, but for my use case actually these headless tables take up the bulk of the application so I do get slightly wary about having to implement some of these things.

Thanks again for the library, however, it’s saved me countless hours over the last month (and will continue to do so)!

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
bryanmyleecommented, Jul 29, 2022

Sure thing, I’l look into providing a selectAll method on the data IDs store that’s bound to the internal row state.

0reactions
bryanmyleecommented, Aug 13, 2022

@MellenIO I’ve added this to the plugin in v0.13.3.

You can find its documentation here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IR rows on "select all" option into collection — oracle-tech
Hello. We are using Oracle Apex 21.2.6. We are trying to fill a collection when user clicks on Interactive Report checkboxes.
Read more >
How can I add a "Select All" option to a jqGrid select toolbar ...
I'm building tables using jqGrid with a filter toolbar to let users filter the rows displayed in the table. This is all working...
Read more >
Select All Checkbox using Select Extension - DataTables
I have this working, but I really want a "select all" checkbox. Ideally it would select all rows when checked, and if a...
Read more >
Select only filtered rows using select all button that comes with ...
I am trying to select only filtered rows using select all button that comes with select extension in shiny's DT package but it...
Read more >
Select all rows in admin. - WordPress.org
Whilst dynamically updating data, noticed a bunch of red rows past row 10. There is no button to select all checkboxes for rows?...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found