daniel-nagy / md-data-table

Material Design Data Table for Angular Material
MIT License
1.9k stars 519 forks source link

How to select all rows? #639

Closed diegoberges closed 5 years ago

diegoberges commented 6 years ago

When I have a lot of rows, and I have pagination, y can only check the rows in the active view.

How can I select all rows? it's possible?

dang-toan commented 6 years ago

Set: <table md-table multiple="true"> View more demo here: https://codepen.io/anon/pen/OZVMJg?editors=1010

diegoberges commented 6 years ago

I need to select all the elements of all the pages, not just the first one.

dang-toan commented 6 years ago

Not support now. You have to do it by yourseft.

diegoberges commented 6 years ago

Do you have any example to try it??

deyvidfk commented 6 years ago

Simple example:

vm.selectAllRows = function () {
     // pre selection of all rows                
    vm.dataGrid.dataSet.forEach(function (item) {
        // set value in mdTableNgModel;
        vm.selectedRow.push(item);
    });
};

// Do not do this: angular.copy (vm.dataGrid.dataSet, vm.selectedRow);
// Also do not do this: vm.selectedRow = vm.dataGrid.dataSet;
// I had referral issues between the instances of the dataset object when I assigned the value to the //NgModelAttribute of mdTableElement because when I unchecked the row mdRowCheckbox 
// the item was automatically removed from the table.   
diegoberges commented 5 years ago

Sorry, you can explain your idea?

I'm editing the file md-data-table.js but I can`t select all rows, I can only select the raws that there are in the first page of table.

Thanks

deyvidfk commented 5 years ago

@diegoberges The variable assigned to the ngModel attribute contains all selected rows from the table, so the idea is basically to copy all items from the dataSource to ngModel, this will tell the table that such rows are selected.

diegoberges commented 5 years ago

Thanks!