Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sortable issue in element-ui

I have wrote the table code by using Element-ui. I need the column sortable, but however it does not work. I have no idea what is the reason. Is it the data format wrong?

great thx

<el-table v-loading="listLoading" :data="list">
  <el-table-column type="selection" >&nbsp;</el-table-column>
  <el-table-column label="NO" fixed width="100" sortable><template slot-scope="scope">{{ scope.row.number }}</template></el-table-column>
  <el-table-column v-for="head in formThead" :key="head.value" :label="head.title" :min-width="head.celwidth ==null ? 100: head.celwidth" :sortable="head.sortable">
    <template slot-scope="scope">
      {{ scope.row[head.value] }}
    </template>
  </el-table-column>
</el-table>


formThead: [
    { value: 'dest', title: 'Dest', celwidth: 110, sortable: true }, { value: 'date', title: 'Date' }, { value: 'pcs', title: 'PCS', celwidth: 80 }],

list:[
  {"number": "2", "dest": "AAA", "date": "2019-01-01", "pcs": "2"},
  {"number": "3", "dest": "ABB", "date": "2019-01-02", "pcs": "1"},
  {"number": "4", "dest": "CAA", "date": "2019-02-11", "pcs": "3"},
  {"number": "6", "dest": "DEA", "date": "2019-03-01", "pcs": "5"}
 ]
like image 658
Ian Avatar asked Mar 31 '26 17:03

Ian


1 Answers

To make sorting working, You need to pass key from data to prop ie prop="number" in el-table-column. For example. If you want to sorting Number column. You need to add prop="number" or any key you want to correspond to data in array which you are using for table

<el-table-column label="NO" prop="number" fixed width="100" sortable>
    <template slot-scope="scope">{{scope.row.number}}</template>
</el-table-column>

And Full Solution to your code with another column sorting

<el-table v-loading="listLoading" :data="list">
      <el-table-column type="selection" >&nbsp;</el-table-column>
      <el-table-column label="NO" fixed width="100" prop="number" sortable><template slot-scope="scope">{{ scope.row.number }}</template></el-table-column>
      <el-table-column v-for="head in formThead" :key="head.value" :prop="head.value" :label="head.title" :min-width="head.celwidth ==null ? 100: head.celwidth" :sortable="head.sortable">
        <template slot-scope="scope">
          {{ scope.row[head.value] }}
        </template>
      </el-table-column>
</el-table>
like image 119
bkawan Avatar answered Apr 02 '26 13:04

bkawan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!