如何在 Quasar / Vue 中将自定义表头正确绑定到数据

Mar*_*son 2 vue.js quasar-framework

我试图覆盖类星体表中的标准标题。主要是因为我需要一个堆叠标题(带有 colspans/rowspans 的 2 行)。我可以让它看起来正确,但我无法让它表现得像一个正确的表头 - 主要是它不会排序。我尝试了几种方法来声明性地绑定它。

<q-table
    :data="data"
    :columns="columns"
    row-key="name" class="col-12">
    <template v-slot:header="props">
      <q-tr :props="props">
          <q-th rowspan="2" >Sku</q-th>
          <q-th rowspan="2">Name</q-th>
          <q-th colspan="3" style="text-align:center">Sales</q-th>
          <q-th rowspan="2" style="text-align:center">Order</q-th>
          <q-th colspan="3" style="text-align:center">Before Order</q-th>
          <q-th colspan="3" style="text-align:center">After Order</q-th>
          <q-th colspan="3" style="text-align:center">Order</q-th>
       </q-tr>
       <q-tr :props="props">
          <q-th>Qty</q-th>
          <q-th>Count</q-th>
          <q-th>Daily</q-th>
          <q-th>Stock</q-th>
          <q-th>Days</q-th>
          <q-th>Date</q-th>
          <q-th>Stock</q-th>
          <q-th>Days</q-th>
          <q-th>Date</q-th>
          <q-th>Price</q-th>
          <q-th>Discount</q-th>
          <q-th>Total</q-th>
       </q-tr>
  </template>
</q-table>
Run Code Online (Sandbox Code Playgroud)

cha*_*ans 7

重构了代码并添加了密钥和单独的道具以与密钥“名称”一起传递到每个标头,现在它按预期工作

工作代码沙箱在这里:https ://codesandbox.io/s/codesandbox-app-edivz

直播页面网址: https: //edivz.sse.codesandbox.io/purchase-orders

<q-table
        :data="data"
        :columns="columns"
        row-key="name" class="col-12">
        <template v-slot:header="props">
          <q-tr>
              <q-th :props="props" key="sku" rowspan="2" >Sku</q-th>
              <q-th :props="props" key="name" rowspan="2">Name</q-th>
              <q-th colspan="3" style="text-align:center">Sales</q-th>
              <q-th :props="props" key="Qty" rowspan="2" style="text-align:center">Order</q-th>
              <q-th colspan="3" style="text-align:center">Before Order</q-th>
              <q-th colspan="3" style="text-align:center">After Order</q-th>
              <q-th colspan="3" style="text-align:center">Order</q-th>
           </q-tr>
           <q-tr>
              <q-th :props="props" key="SalesQty">Qty</q-th>
              <q-th :props="props" key="SalesCount">Count</q-th>
              <q-th :props="props" key="DailySales">Daily</q-th>
              <q-th :props="props" key="BeforeOrderQty">Stock</q-th>
              <q-th :props="props" key="BeforeOrderDays">Days</q-th>
              <q-th :props="props" key="BeforeOrderDate">Date</q-th>
              <q-th :props="props" key="AfterOrderQty">Stock</q-th>
              <q-th :props="props" key="AfterOrderDays">Days</q-th>
              <q-th :props="props" key="AfterOrderDate">Date</q-th>
              <q-th :props="props" key="Price">Price</q-th>
              <q-th :props="props" key="Discount">Discount</q-th>
              <q-th :props="props" key="Total">Total</q-th>
           </q-tr>
      </template>

      </q-table>
Run Code Online (Sandbox Code Playgroud)