Skip to content

Commit fea4577

Browse files
committed
refactor: CTable: delete indexColumn prop
1 parent 3746e8f commit fea4577

File tree

4 files changed

+13
-72
lines changed

4 files changed

+13
-72
lines changed

src/components/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,6 @@ export declare class CTable extends Vue {
562562
fields: Array<any>
563563
itemsPerPage: number
564564
activePage: number
565-
indexColumn: boolean
566565
filterRow: boolean
567566
pagination: [boolean, object]
568567
addTableClasses: [string, Array<any>, object]

src/components/table/CTable.vue

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
<table :class="tableClasses">
4848
<thead>
4949
<tr>
50-
<th v-if="indexColumn" style="width:40px"></th>
5150
<template v-for="(name, index) in columnNames">
5251
<th
5352
@click="changeSort(rawColumnNames[index], index)"
@@ -74,7 +73,6 @@
7473
</tr>
7574

7675
<tr v-if="columnFilter" class="table-sm">
77-
<th v-if="indexColumn"></th>
7876
<template v-for="(colName, index) in rawColumnNames" >
7977
<th :class="headerClass(index)" :key="index">
8078
<slot :name="`${rawColumnNames[index]}-filter`">
@@ -102,16 +100,6 @@
102100
@click="rowClicked(item, itemIndex + firstItemIndex)"
103101
:key="itemIndex"
104102
>
105-
<slot
106-
v-if="indexColumn"
107-
name="index-column"
108-
:pageIndex="itemIndex"
109-
:index="firstItemIndex + itemIndex"
110-
>
111-
<td>
112-
{{ firstItemIndex + itemIndex + 1 }}
113-
</td>
114-
</slot>
115103
<template v-for="(colName, index) in rawColumnNames" >
116104
<slot
117105
v-if="$scopedSlots[colName]"
@@ -165,9 +153,8 @@
165153
</tbody>
166154

167155

168-
<tfoot v-if="footer && currentItems.length > 3">
156+
<tfoot v-if="footer && currentItems.length > 0">
169157
<tr>
170-
<th v-if="indexColumn" style="width:40px"></th>
171158
<template v-for="(name, index) in columnNames">
172159
<th
173160
@click="changeSort(rawColumnNames[index], index)"
@@ -240,7 +227,6 @@ export default {
240227
default: 10
241228
},
242229
activePage: Number,
243-
indexColumn: Boolean,
244230
columnFilter: Boolean,
245231
pagination: [Boolean, Object],
246232
addTableClasses: [String, Array, Object],
@@ -375,7 +361,7 @@ export default {
375361
return {'position-relative pr-4' : this.sortable }
376362
},
377363
colspan () {
378-
return this.rawColumnNames.length + (this.indexColumn ? 1 : 0)
364+
return this.rawColumnNames.length
379365
},
380366
isFiltered () {
381367
return this.tableFilterVal || Object.values(this.columnFilterVal).join('')

src/components/table/tests/CTable.spec.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const customWrapper = mount(Component, {
2929
{ key: 'show_details' , label:'', _style:'width:1%', sortable: false, filterable: false },
3030
],
3131

32-
indexColumn: true,
3332
tableFilter: true,
3433
itemsPerPageSelect: true,
3534
addTableClasses: 'additional-table-class',
@@ -61,26 +60,26 @@ describe(ComponentName, () => {
6160
})
6261
it('changes sorting correctly', () => {
6362
expect(customWrapper.vm.sortedItems[0].username).toBe('Yiorgos Avraamu')
64-
customWrapper.find('tr').findAll('th').at(4).trigger('click')
63+
customWrapper.find('tr').findAll('th').at(3).trigger('click')
6564
expect(customWrapper.vm.sortedItems[0].status).toBe('Active')
6665

67-
customWrapper.find('tr').findAll('th').at(4).trigger('click')
66+
customWrapper.find('tr').findAll('th').at(3).trigger('click')
6867
expect(customWrapper.vm.sortedItems[0].status).toBe('Pending')
6968
})
70-
it('doesnt change sorter when clicked on noSortable column', () => {
69+
it('doesnt change sorter when clicked on not sortable column', () => {
7170
const oldSorterColumn = customWrapper.vm.sorter.column
72-
customWrapper.find('tr').findAll('th').at(5).trigger('click')
71+
customWrapper.find('tr').findAll('th').at(4).trigger('click')
7372
expect(customWrapper.vm.sorter.column).toBe(oldSorterColumn)
7473
})
7574
it('renders pretified column names when fields are not defined', () => {
7675
customWrapper.setProps({ fields: undefined })
7776
expect(customWrapper.vm.columnNames[0]).toBe('Username')
7877
})
79-
it('changes colspan when indexColumn is switched', () => {
80-
const colspanWithIndexColumn = customWrapper.vm.colspan
81-
customWrapper.setProps({ indexColumn: false })
82-
expect(customWrapper.vm.colspan).toBe(colspanWithIndexColumn - 1)
83-
})
78+
// it('changes colspan when indexColumn is switched', () => {
79+
// const colspanWithIndexColumn = customWrapper.vm.colspan
80+
// customWrapper.setProps({ indexColumn: false })
81+
// expect(customWrapper.vm.colspan).toBe(colspanWithIndexColumn - 1)
82+
// })
8483
it('table filter works correctly', () => {
8584
customWrapper.setData({ tableFilterVal: 'Yiorgos' })
8685
expect(customWrapper.vm.sortedItems.length).toBe(1)

src/components/table/tests/__snapshots__/CTable.spec.js.snap

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ exports[`CTable renders correctly 1`] = `
1111
class="table"
1212
>
1313
<thead>
14-
<tr>
15-
<!---->
16-
17-
</tr>
14+
<tr />
1815
1916
<!---->
2017
</thead>
@@ -159,10 +156,6 @@ exports[`CTable renders correctly 2`] = `
159156
>
160157
<thead>
161158
<tr>
162-
<th
163-
style="width: 40px;"
164-
/>
165-
166159
<th
167160
class="user-custom-class position-relative pr-4"
168161
style="cursor: pointer; width: 40%;"
@@ -308,8 +301,6 @@ exports[`CTable renders correctly 2`] = `
308301
<tr
309302
class="table-sm"
310303
>
311-
<th />
312-
313304
<th
314305
class="user-custom-class"
315306
>
@@ -352,12 +343,6 @@ exports[`CTable renders correctly 2`] = `
352343
class="position-relative"
353344
>
354345
<tr>
355-
<td>
356-
357-
1
358-
359-
</td>
360-
361346
<td
362347
class="user-custom-class"
363348
>
@@ -397,12 +382,6 @@ exports[`CTable renders correctly 2`] = `
397382
398383
<!---->
399384
<tr>
400-
<td>
401-
402-
2
403-
404-
</td>
405-
406385
<td
407386
class="user-custom-class"
408387
>
@@ -442,12 +421,6 @@ exports[`CTable renders correctly 2`] = `
442421
443422
<!---->
444423
<tr>
445-
<td>
446-
447-
3
448-
449-
</td>
450-
451424
<td
452425
class="user-custom-class"
453426
>
@@ -487,12 +460,6 @@ exports[`CTable renders correctly 2`] = `
487460
488461
<!---->
489462
<tr>
490-
<td>
491-
492-
4
493-
494-
</td>
495-
496463
<td
497464
class="user-custom-class"
498465
>
@@ -532,12 +499,6 @@ exports[`CTable renders correctly 2`] = `
532499
533500
<!---->
534501
<tr>
535-
<td>
536-
537-
5
538-
539-
</td>
540-
541502
<td
542503
class="user-custom-class"
543504
>
@@ -582,10 +543,6 @@ exports[`CTable renders correctly 2`] = `
582543
583544
<tfoot>
584545
<tr>
585-
<th
586-
style="width: 40px;"
587-
/>
588-
589546
<th
590547
class="user-custom-class position-relative pr-4"
591548
style="cursor: pointer; width: 40%;"
@@ -739,7 +696,7 @@ exports[`CTable renders correctly 2`] = `
739696
style="display: none;"
740697
>
741698
<ul
742-
class="pagination pagination-md justify-content-start"
699+
class="pagination justify-content-start"
743700
>
744701
<li
745702
class="page-item disabled"

0 commit comments

Comments
 (0)