Skip to content
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

[Feature Request] Ability to hide rows #376

Open
573927 opened this issue Apr 2, 2024 · 6 comments
Open

[Feature Request] Ability to hide rows #376

573927 opened this issue Apr 2, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@573927
Copy link

573927 commented Apr 2, 2024

It would be great to have a method to toggle visibility of rows. At the moment I use a button that toggles visibility via CSS and a class, but this method doesn't update the info "Showing x to y of z entries".

@johanneswilm
Copy link
Member

Can you not filter for the rows you need?

@johanneswilm johanneswilm added the enhancement New feature or request label Apr 10, 2024
@573927
Copy link
Author

573927 commented Apr 11, 2024

Filtering on the fly works great in general. However, my use case is to have a table that contains tasks. Some are completed, some not. It would be nice to be able to programmatically hide the completed rows on initial table display and have a button to toggle their visibility. I am guessing the logic used for the normal filtering could be used for this, but being a JS newbie, I didn't yet understand that well enough to add this functionality myself.

@arcangelochine
Copy link

I think you should filter by a flag that is set when you click your completion button.

@AndreaGelmini
Copy link

AndreaGelmini commented Apr 23, 2024

Hello, I think this is a very specific behavior, given the use case. I would see it as a good solution added by a potential plugin, similar to how the column filter and editor work.
So, off the cuff, it could be done in this way, perhaps.

const Table = new DataTable('#table', {
	paging: false,
	rowNavigation: false,
	tabIndex: 1,
	columns: [
		{select: 5, render: (data, cell, row) => {
			if (  data.flag === 'complete' ) {
				row.classList.add('hidden');
			}
			return data;
		}
		]
});

I have not tested it, but it should work. Assuming that in column 5, which would be column 6 visually, if the "flag" content is identical to "complete", then add the "hidden" class to the row.
I recommend doing a console.log of data, col, row.
Now, the issue is that every time someone clicks on the "completed" button, you need to activate an action that destroys the table, reloads updated data, and then regenerates the table.
You should use these actions.
https://fiduswriter.github.io/simple-datatables/documentation/Events#datatablerefresh
https://fiduswriter.github.io/simple-datatables/documentation/Events#datatableupdate

The technique I am using for my use case is as follows. However, I need to make the one-time row transparent.

    hideRow(e) {
        const tr = e.target.closest('tr');

        tr.classList.remove('opacity-100');
        tr.classList.add('opacity-0');

        let handleAnimationEnd = () => {
            tr.classList.add('hidden');
            tr.removeEventListener("transitionend", handleAnimationEnd);
        }

        tr.addEventListener("transitionend", handleAnimationEnd);

        return;
    }

@johanneswilm
Copy link
Member

@AndreaGelmini Thanks for this example. I am sure that others will find it useful. One thing to keep in mind is that this likely won't work if you use pagination as the engine doesn't know which rows are shown and which ones are not. In those cases one would instead have to do as arcangelochine suggests.

@AndreaGelmini
Copy link

AndreaGelmini commented Apr 23, 2024

I apologize. I forgot to mention that in my use case, the button is inside a cell in every row. Therefore, const tr = e.target.closest('tr'); it accurately hides the row that I need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants