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.

<b-table> mark rows as unselectable

See original GitHub issue

In my application the table serves both to display data and allow the “owner” of the data to the change the state of the rows by selecting them and then clicking a button. However some rows are in a state which allowing them to be changed doesn’t make sense.

It would be great if the row object could specify a _selectable boolean (like _showDetails) which enable/disable the ability to select the row. (If the row is in a range being selected, it is just omitted from the range).

You’d also have to decide how to handle the row being clicked with range mode (do nothing? select all the rows up to but not including the row?).

I’m sure there’s a workaround where I listen for clicks and then conditionally deselect the row immediately, so consider this low priority.

I also understand if this is too niche to justify the complexity.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
siddiqian-developercommented, Aug 4, 2021

I did a very short solution based on @sandrovw64 's solution above.

After adding the _rowVariant, which will appear as a class in each which is to be unselectable, make it unselectable in CSS as following:

.table-row-disabled { pointer-events: none !important; }

2reactions
sandrovw64commented, Nov 24, 2020

For those who needs a disabled row in a <b-table>, here is my implementation:

<b-table ref="table"
              :fields="table.fields"
              hover
              :items="items"
              select-mode="multi"
              selectable
              thead-class="d-none"
              @row-selected="onRowSelected">
...
computed: {
    items() {
      var items = [];
      if (this.list.items.length > 0) {
        items = Object.assign([], this.list.items);
        items.forEach((item) => {
          if (this.getDisabled(item)) {
            item = this.setRowVariant(item);
          }
        });
      }
      return items;
    },
...
methods: {
    onRowSelected(items) {
      var selected = [];
      items.forEach((element, index) => {
        if (this.getDisabled(element)) {
            this.$refs.table.unselectRow(index);
        } else {
          selected.push(element);
        }
      });
      this.selected = selected;
    },
    setRowVariant(item) {
      return (item._rowVariant = "row-disabled");
    },
}
...

And then, in my custom table.scss file I added

.table-hover .table-row-disabled:hover {
  background-color: var(--gray-2);
  cursor: not-allowed !important; 
}

Notice the .table-hover class. My b-table is set to hover. If yours is not, then just use .table

Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS rule to disable highlighting table column upon selection
The user simply should not be able to highlight (select) the (✘) because it is set to unselectable . Environment. I am using...
Read more >
Why is Repeat Headers grayed out? - Microsoft Community
Click in the Header Row then go to Table> Table Properties.... in the main menu, or; Right-click in the Header Row & select...
Read more >
Solved: disable selectable value from table
Solved: I am distributing a report to many people and I want to disable their ability to select values in a table since...
Read more >
UnSelectable Rows in Jquery DataTable?
Hi, On Some button click, i want to view some rows in data table are unselectable or unclickable(i.e disable) and other rows are...
Read more >
How to make specific cells unselectable in Excel? - ExtendOffice
Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select... Exact...
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