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

No way to get the list of checked rows in a data table #1210

Closed
tleunen opened this issue Jul 25, 2015 · 8 comments
Closed

No way to get the list of checked rows in a data table #1210

tleunen opened this issue Jul 25, 2015 · 8 comments
Assignees
Milestone

Comments

@tleunen
Copy link
Contributor

tleunen commented Jul 25, 2015

How can we get the list of checked rows in a data-table if this one is selectable?
Would it be possible to get a event when a row is checked/unchecked, or maybe a new getter?

@Garbee
Copy link
Collaborator

Garbee commented Jul 25, 2015

An event sounds reasonable. I don't see where a getter would really be useful to add in. It saves only a few lines of code in the end.

@nicolasgarnier
Copy link
Contributor

Arguably you can already do this by adding an event on each checkbox no? Like that:

  var checkboxes = document.getElementById('myTableId').querySelector('tbody').querySelectorAll('.mdl-checkbox__input');
  for (var i = 0; i < checkboxes.length; i++) {
    checkboxes[i].addEventListener('change', listener);
  }

The above should be enough, especially after #1170 lands.

I could add the following to the DataTable's proto but is it really worth it since we're trying to stay "light"? :)

/**
 * Adds an event listener on the table's checkboxes.
 */
MaterialDataTable.prototype.addEventListener = function(type, listener,
                                                        useCapture) {
  'use strict';

  var checkboxes = this.element_.querySelector('tbody').querySelectorAll('.mdl-checkbox__input');
  for (var i = 0; i < checkboxes.length; i++) {
    checkboxes[i].addEventListener(type, listener, useCapture);
  }
};

@tleunen
Copy link
Contributor Author

tleunen commented Aug 5, 2015

Of course there's a way to get that information.. But I still think it's something that should be included in the library.

What's the point of having a feature to add checkboxes in the datatable if there's no way of getting the result of them with the library?

@thanhmabo
Copy link

How add name and value for checkbox, @tleunen , have u find solution?

@nicolasgarnier
Copy link
Contributor

@thanhmabo To do this easily you have to wait until #1170 is merged and for the next release which should be v1.1.
In the mean time you can do this programmatically: give an ID to your <tr> and get the checkbox with a selector like that:

document.getElementById('myTRId').querySelector('.mdl-checkbox__input').name = 'myCheckboxInputName';

@tleunen I discussed with the rest of the team and we decided to add the event on data-table. I'll get started on that. Probably this will make it into 1.1 too :)

@tleunen
Copy link
Contributor Author

tleunen commented Aug 7, 2015

Thanks @nicolasgarnier :) 🙌

@Garbee
Copy link
Collaborator

Garbee commented Oct 20, 2015

We are officially deprecating the automatic checkbox generation for data tables. Please see the wiki page for instructions on how this should be replaced in your current code. The new method allows developers more control over the checkboxes in every way, as well as more intuitive removing and adding new rows.

Due to this deprecation we will not be adding this or any other new functionality for this component's JS.

@slippyC
Copy link

slippyC commented Dec 31, 2017

Just a heads up for anyone that cares. If dynamically adding, even after you do componentHandler.upgradeElement(whatever) The ripple effect that is on the label will not respond like the ripple on static labels. I don't know if the timing is quicker or what, but it is visually faster or at least different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants