stk-table-vue 0.4.8 → 0.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1122,17 +1122,18 @@ const _hoisted_6 = [
1122
1122
  ];
1123
1123
  const _hoisted_7 = ["onMousedown"];
1124
1124
  const _hoisted_8 = ["onMousedown"];
1125
- const _hoisted_9 = {
1125
+ const _hoisted_9 = { class: "stk-tbody-main" };
1126
+ const _hoisted_10 = {
1126
1127
  key: 0,
1127
1128
  class: "vt-x-left"
1128
1129
  };
1129
- const _hoisted_10 = ["id", "data-row-key", "onClick", "onDblclick", "onContextmenu", "onMouseover"];
1130
- const _hoisted_11 = {
1130
+ const _hoisted_11 = ["id", "data-row-key", "onClick", "onDblclick", "onContextmenu", "onMouseover"];
1131
+ const _hoisted_12 = {
1131
1132
  key: 0,
1132
1133
  class: "vt-x-left"
1133
1134
  };
1134
- const _hoisted_12 = ["data-index", "onClick", "onMouseenter", "onMouseleave", "onMouseover"];
1135
- const _hoisted_13 = ["title"];
1135
+ const _hoisted_13 = ["data-index", "onClick", "onMouseenter", "onMouseleave", "onMouseover"];
1136
+ const _hoisted_14 = ["title"];
1136
1137
  const _sfc_main = /* @__PURE__ */ defineComponent({
1137
1138
  __name: "StkTable",
1138
1139
  props: {
@@ -1468,9 +1469,22 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1468
1469
  const sortConfig = props.sortConfig;
1469
1470
  const defaultSort = sortConfig.defaultSort;
1470
1471
  if (!order && defaultSort) {
1471
- order = defaultSort.order;
1472
+ if (!defaultSort.dataIndex) {
1473
+ console.error("sortConfig.defaultSort.dataIndex is required");
1474
+ return;
1475
+ }
1476
+ order = defaultSort.order || "desc";
1472
1477
  sortOrderIndex.value = sortSwitchOrder.indexOf(order);
1473
1478
  sortCol.value = defaultSort.dataIndex;
1479
+ const c = props.columns.find((item) => item.dataIndex === defaultSort.dataIndex);
1480
+ if (c) {
1481
+ col = c;
1482
+ } else {
1483
+ console.error("defaultSort.dataIndex not found in columns");
1484
+ col = props.columns[0];
1485
+ }
1486
+ if (!col)
1487
+ return;
1474
1488
  }
1475
1489
  if (!props.sortRemote || options.force) {
1476
1490
  dataSourceCopy.value = tableSort(col, order, props.dataSource, sortConfig);
@@ -1668,6 +1682,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1668
1682
  class: normalizeClass(["stk-table", {
1669
1683
  virtual: _ctx.virtual,
1670
1684
  "virtual-x": _ctx.virtualX,
1685
+ "vt-on": unref(virtual_on),
1671
1686
  dark: _ctx.theme === "dark",
1672
1687
  headless: _ctx.headless,
1673
1688
  "is-col-resizing": unref(isColResizing),
@@ -1783,15 +1798,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1783
1798
  ], 32);
1784
1799
  }), 128))
1785
1800
  ], 512)) : createCommentVNode("", true),
1786
- createElementVNode("tbody", {
1787
- class: normalizeClass(["stk-tbody-main", unref(virtual_on) ? "vt-on" : "vt-off"])
1788
- }, [
1801
+ createElementVNode("tbody", _hoisted_9, [
1789
1802
  unref(virtual_on) ? (openBlock(), createElementBlock("tr", {
1790
1803
  key: 0,
1791
1804
  style: normalizeStyle(`height:${unref(virtualScroll).offsetTop}px`),
1792
1805
  class: "padding-top-tr"
1793
1806
  }, [
1794
- unref(virtualX_on) && _ctx.fixedMode && _ctx.headless ? (openBlock(), createElementBlock("td", _hoisted_9)) : createCommentVNode("", true),
1807
+ unref(virtualX_on) && _ctx.fixedMode && _ctx.headless ? (openBlock(), createElementBlock("td", _hoisted_10)) : createCommentVNode("", true),
1795
1808
  _ctx.fixedMode && _ctx.headless ? (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(unref(virtualX_columnPart), (col) => {
1796
1809
  return openBlock(), createElementBlock("td", {
1797
1810
  key: col.dataIndex,
@@ -1814,7 +1827,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1814
1827
  onContextmenu: (e) => onRowMenu(e, row),
1815
1828
  onMouseover: (e) => onTrMouseOver(e, row)
1816
1829
  }, [
1817
- unref(virtualX_on) ? (openBlock(), createElementBlock("td", _hoisted_11)) : createCommentVNode("", true),
1830
+ unref(virtualX_on) ? (openBlock(), createElementBlock("td", _hoisted_12)) : createCommentVNode("", true),
1818
1831
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(virtualX_columnPart), (col, colIndex) => {
1819
1832
  return openBlock(), createElementBlock("td", {
1820
1833
  key: col.dataIndex,
@@ -1843,16 +1856,16 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1843
1856
  ], 64)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
1844
1857
  createTextVNode(toDisplayString((row == null ? void 0 : row[col.dataIndex]) ?? getEmptyCellText.value(col, row)), 1)
1845
1858
  ], 64))
1846
- ], 8, _hoisted_13))
1847
- ], 46, _hoisted_12);
1859
+ ], 8, _hoisted_14))
1860
+ ], 46, _hoisted_13);
1848
1861
  }), 128))
1849
- ], 42, _hoisted_10);
1862
+ ], 42, _hoisted_11);
1850
1863
  }), 128)),
1851
1864
  unref(virtual_on) ? (openBlock(), createElementBlock("tr", {
1852
1865
  key: 1,
1853
1866
  style: normalizeStyle(`height: ${unref(virtual_offsetBottom)}px`)
1854
1867
  }, null, 4)) : createCommentVNode("", true)
1855
- ], 2)
1868
+ ])
1856
1869
  ], 6),
1857
1870
  (!dataSourceCopy.value || !dataSourceCopy.value.length) && _ctx.showNoData ? (openBlock(), createElementBlock("div", {
1858
1871
  key: 1,
package/lib/style.css CHANGED
@@ -91,16 +91,22 @@
91
91
  .stk-table.border-body-v tbody{
92
92
  --bg-border-bottom:linear-gradient(transparent, transparent);
93
93
  }
94
- .stk-table.stripe .stk-tbody-main.vt-on tr:nth-child(odd){
94
+ .stk-table.stripe .stk-tbody-main tr:nth-child(even){
95
95
  background-color:var(--stripe-bgc);
96
96
  }
97
- .stk-table.stripe .stk-tbody-main.vt-off tr:nth-child(even){
97
+ .stk-table.stripe.vt-on .stk-tbody-main tr:nth-child(odd){
98
98
  background-color:var(--stripe-bgc);
99
99
  }
100
- .stk-table.row-hover tbody tr:hover{
100
+ .stk-table.stripe.row-hover .stk-tbody-main tr:hover{
101
101
  background-color:var(--tr-hover-bgc);
102
102
  }
103
- .stk-table.row-active tbody tr.active{
103
+ .stk-table.stripe.row-active .stk-tbody-main tr.active{
104
+ background-color:var(--tr-active-bgc);
105
+ }
106
+ .stk-table.row-hover .stk-tbody-main tr:hover{
107
+ background-color:var(--tr-hover-bgc);
108
+ }
109
+ .stk-table.row-active .stk-tbody-main tr.active{
104
110
  background-color:var(--tr-active-bgc);
105
111
  }
106
112
  .stk-table.cell-hover tbody td:hover{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stk-table-vue",
3
- "version": "0.4.8",
3
+ "version": "0.4.9",
4
4
  "description": "Simple realtime virtual table for vue3 and vue2.7",
5
5
  "main": "./lib/stk-table-vue.js",
6
6
  "types": "./lib/src/StkTable/index.d.ts",
@@ -6,6 +6,7 @@
6
6
  :class="{
7
7
  virtual,
8
8
  'virtual-x': virtualX,
9
+ 'vt-on': virtual_on,
9
10
  dark: theme === 'dark',
10
11
  headless,
11
12
  'is-col-resizing': isColResizing,
@@ -121,7 +122,7 @@
121
122
  <!-- 用于虚拟滚动表格内容定位 @deprecated 有兼容问题-->
122
123
  <!-- <tbody v-if="virtual_on" :style="{ height: `${virtualScroll.offsetTop}px` }"></tbody> -->
123
124
  <!-- <tbody :style="{ transform: `translateY(${virtualScroll.offsetTop}px)` }"> -->
124
- <tbody class="stk-tbody-main" :class="virtual_on ? 'vt-on' : 'vt-off'">
125
+ <tbody class="stk-tbody-main">
125
126
  <tr v-if="virtual_on" :style="`height:${virtualScroll.offsetTop}px`" class="padding-top-tr">
126
127
  <!--这个td用于配合虚拟滚动的th对应,防止列错位-->
127
128
  <td v-if="virtualX_on && fixedMode && headless" class="vt-x-left"></td>
@@ -855,10 +856,22 @@ function onColumnSort(col?: StkTableColumn<DT>, click = true, options: { force?:
855
856
  const defaultSort = sortConfig.defaultSort;
856
857
 
857
858
  if (!order && defaultSort) {
859
+ if (!defaultSort.dataIndex) {
860
+ console.error('sortConfig.defaultSort.dataIndex is required');
861
+ return;
862
+ }
858
863
  // 没有排序时变成默认排序
859
- order = defaultSort.order;
864
+ order = defaultSort.order || 'desc';
860
865
  sortOrderIndex.value = sortSwitchOrder.indexOf(order);
861
866
  sortCol.value = defaultSort.dataIndex as string;
867
+ const c = props.columns.find(item => item.dataIndex === defaultSort.dataIndex);
868
+ if (c) {
869
+ col = c;
870
+ } else {
871
+ console.error('defaultSort.dataIndex not found in columns');
872
+ col = props.columns[0];
873
+ }
874
+ if (!col) return;
862
875
  }
863
876
  if (!props.sortRemote || options.force) {
864
877
  dataSourceCopy.value = tableSort(col, order, props.dataSource, sortConfig);
@@ -134,23 +134,31 @@
134
134
  }
135
135
 
136
136
  /* 斑马纹*/
137
- &.stripe .stk-tbody-main {
138
-
139
- &.vt-on tr:nth-child(odd) {
137
+ &.stripe {
138
+ .stk-tbody-main tr:nth-child(even) {
140
139
  background-color: var(--stripe-bgc);
141
140
  }
142
141
 
143
- &.vt-off tr:nth-child(even) {
142
+ &.vt-on .stk-tbody-main tr:nth-child(odd) {
144
143
  background-color: var(--stripe-bgc);
145
144
  }
145
+
146
+ &.row-hover .stk-tbody-main tr:hover {
147
+ background-color: var(--tr-hover-bgc);
148
+ }
149
+
150
+ &.row-active .stk-tbody-main tr.active {
151
+ background-color: var(--tr-active-bgc);
152
+ }
146
153
  }
147
154
 
148
- &.row-hover tbody tr:hover {
155
+
156
+ &.row-hover .stk-tbody-main tr:hover {
149
157
  background-color: var(--tr-hover-bgc);
150
158
  }
151
159
 
152
160
 
153
- &.row-active tbody tr.active {
161
+ &.row-active .stk-tbody-main tr.active {
154
162
  background-color: var(--tr-active-bgc);
155
163
  }
156
164