Maison  >  Questions et réponses  >  le corps du texte

La colonne de droite de la table bootstrap-vue peut-elle être corrigée ?

Je veux des colonnes fixes correctes dans la table bootstrap-vue Cependant, la fonctionnalité Sticky dans le document n'est corrigée que sur le côté gauche. Existe-t-il un moyen de corriger la bonne ou la dernière colonne ?

Je souhaite que les colonnes gauche et droite soient fixées en place.

Site Web de documentation : https://bootstrap-vue.org/docs/components/table#sticky-columns

<template>
  <div>
    <div class="mb-2">
      <b-form-checkbox v-model="stickyHeader" inline>Sticky header</b-form-checkbox>
      <b-form-checkbox v-model="noCollapse" inline>No border collapse</b-form-checkbox>
    </div>
    <b-table
      :sticky-header="stickyHeader"
      :no-border-collapse="noCollapse"
      responsive
      :items="items"
      :fields="fields"
    >
      <!-- We are using utility class `text-nowrap` to help illustrate horizontal scrolling -->
      <template #head(id)="scope">
        <div class="text-nowrap">Row ID</div>
      </template>
      <template #head()="scope">
        <div class="text-nowrap">
          Heading {{ scope.label }}
        </div>
      </template>
    </b-table>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        stickyHeader: true,
        noCollapse: false,
        fields: [
          { key: 'id', stickyColumn: true, isRowHeader: true, variant: 'primary' },
          'a',
          'b',
          { key: 'c', stickyColumn: true, variant: 'info' },
          'd',
          'e',
          'f',
          'g',
          'h',
          'i',
          'j',
          'k',
          'l'
        ],
        items: [
          { id: 1, a: 0, b: 1, c: 2, d: 3, e: 4, f: 5, g: 6, h: 7, i: 8, j: 9, k: 10, l: 11 },
          { id: 2, a: 0, b: 1, c: 2, d: 3, e: 4, f: 5, g: 6, h: 7, i: 8, j: 9, k: 10, l: 11 },
          { id: 3, a: 0, b: 1, c: 2, d: 3, e: 4, f: 5, g: 6, h: 7, i: 8, j: 9, k: 10, l: 11 },
          { id: 4, a: 0, b: 1, c: 2, d: 3, e: 4, f: 5, g: 6, h: 7, i: 8, j: 9, k: 10, l: 11 },
          { id: 5, a: 0, b: 1, c: 2, d: 3, e: 4, f: 5, g: 6, h: 7, i: 8, j: 9, k: 10, l: 11 },
          { id: 6, a: 0, b: 1, c: 2, d: 3, e: 4, f: 5, g: 6, h: 7, i: 8, j: 9, k: 10, l: 11 },
          { id: 7, a: 0, b: 1, c: 2, d: 3, e: 4, f: 5, g: 6, h: 7, i: 8, j: 9, k: 10, l: 11 },
          { id: 8, a: 0, b: 1, c: 2, d: 3, e: 4, f: 5, g: 6, h: 7, i: 8, j: 9, k: 10, l: 11 },
          { id: 9, a: 0, b: 1, c: 2, d: 3, e: 4, f: 5, g: 6, h: 7, i: 8, j: 9, k: 10, l: 11 },
          { id: 10, a: 0, b: 1, c: 2, d: 3, e: 4, f: 5, g: 6, h: 7, i: 8, j: 9, k: 10, l: 11 }
        ]
      }
    }
  }
</script>


P粉226667290P粉226667290283 Il y a quelques jours408

répondre à tous(1)je répondrai

  • P粉320361201

    P粉3203612012024-01-11 13:34:14

    Cela peut être réalisé en remplaçant le CSS de bootstrap par certains de nos propres CSS. Assurez-vous d'abord que la dernière colonne contient l'option stickyColumn: true et toutes les autres options que vous souhaitez lui donner : 

    ...
    'i',
    'j',
    'k',
    { key: "l", stickyColumn: true, isRowHeader: true, variant: "primary" },
    

    Cela garantira qu’il aura un nom de classe que nous pourrons facilement choisir. Appliquer un style donnant à la dernière colonne collante du tableau l'attribut right: 0:

    <style>
    .b-table-sticky-column:last-child {
      right: 0;
    }
    </style>
    

    exemple de codesandbox

    répondre
    0
  • Annulerrépondre