5

I am struggling to remove the dropdown arrow next to the column names 'Name', 'Datum', 'Creator'... The dropdown arrow gets rendered in an i-Tag, and if I edit the html via Chrome and add 'display: none' it gets removed...

the arrow next to 'Name' etc.

the dropdown arrow tag

however I am unable to access the i tag or the class v-icon via css in the code. Probably because it is not created before the rendering process.

Is there any other way to remove the dropdown arrow?

Thanks in advance!

Html of my table, called 'file-list':

the html

J. Wu
  • 69
  • 1
  • 1
  • 7
  • 2
    If you don't mind sorting, add `sortable: false` to your `headers` items : `headers: [ { text: 'ID', value: 'Id', sortable: false }, . . . ]` – Toodoo Oct 16 '18 at 08:05
  • Great idea, thanks! That removed the arrows. But I mind sorting :( – J. Wu Oct 16 '18 at 08:14
  • See [this answer](https://stackoverflow.com/a/50985784/1981247) to understand why you are unable to target it, and how to actually target it. – Traxo Oct 16 '18 at 08:32
  • That is correct only if @J.Wu is using **scoped** style – Nati Mask Oct 16 '18 at 08:34
  • 1
    @NatiMask Odds are that they are using scoped style because OP said `however I am unable to access the i tag or the class v-icon via css in the code. Probably because it is not created before the rendering process.`, this indicates to me that they know how to actually target it via CSS, but something is not working. And even if they aren't using scoped styles, other things such as specificity are covered. That should be enough to properly target any element. If something is not clear or covered, feedback is welcome (there). – Traxo Oct 16 '18 at 08:36
  • Great, edited and mentioned in answer – Nati Mask Oct 16 '18 at 08:43

4 Answers4

15

The best way to hide the sort icon is via header-props. For example:

<v-data-table
  :headers="headers"
  :items="items"
  :header-props="{ sortIcon: null }"
>
David Gay
  • 1,094
  • 2
  • 16
  • 32
3

First, I'm pretty sure that you can access this <i> icon tag with css, because the fact that some element will get created dynamically does not preventing it to be affected by your css.

Sure your css could get overridden because of Vuetify css, according to the rules of specificity. I would suggest beginning with add a class property to the <v-data-table>, to allow you to specify the css for the tag something like that:

.my-datatable-class .datatable thead th.column.sortable i {
    display: none;
}

It's different if you are using scoped style, this, and more about css specificity is covered here, thanks @Traxo

Anoter option is to implement the whole header section of the data-table by yourself, which is allowed by Vuetify using scoped-slots example of how to do it is in the examples, look for the Slot: items and headers and there at the template code you can see the <v-icon small>arrow_upward</v-icon> thing, just implement the headers omitting that, and there you go without css, adding something like that into your <v-data-table>:

<template slot="headers" slot-scope="props">
  <tr>
    <th
      v-for="header in props.headers"
      :key="header.text"
      :class="['column sortable', pagination.descending ? 'desc' : 'asc', header.value === pagination.sortBy ? 'active' : '']"
      @click="changeSort(header.value)"
    >
      {{ header.text }}
    </th>
  </tr>
</template>
Nati Mask
  • 676
  • 1
  • 5
  • 12
2

use sortable option false to the necessary columns

ex-:

headers: [{ text: 'Name', value: 'name', sortable: false },
          { text: 'Date', value: 'date', sortable: false }]
Kaumadie Kariyawasam
  • 1,232
  • 3
  • 17
  • 35
1

It is not needed to write any custom CSS. Just possible to use provided vuetify property

sort-icon

It is enough to provide the value of sort-icon as false. It will hide sorting icon of all columns, as I see it is what you need.

<v-data-table
    :headers="headers"
    :items="items"
    :sort-icon="false"
  >
Don D
  • 726
  • 1
  • 9
  • 19
  • 1
    This method has been removed. Now you should use `header-props`, as shown in my answer: https://stackoverflow.com/a/62027761/1196465 – David Gay May 26 '20 at 17:16
  • @DavidGay In the verion I have tested it was working fine. It was "bootstrap": "4.4.1", "bootstrap-vue": "2.9.0". Thanks for pointing out. – Don D May 26 '20 at 19:18
  • No worries, I think you may have gotten confused: This question is about Vuetify (https://vuetifyjs.com/), not BootstrapVue, which is a different component framework (https://bootstrap-vue.org/). – David Gay May 26 '20 at 19:50
  • Oh my bad. My answer was from vuetify. But mistakenly my comment is from bootstrap-vue. I work with both and mistakenly swapped them in the comment. :D And for the vuetify I was referring to 1.5.x and it seems to be removed in vuetify 2. – Don D May 26 '20 at 20:43