AdvancedTable.vue 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711
  1. <template>
  2. <div>
  3. <div
  4. class="table-outer-container"
  5. @mousemove="columnResizing($event)"
  6. @touchmove="columnResizing($event)"
  7. >
  8. <div class="table-header">
  9. <div>
  10. <tippy
  11. v-if="filters.length > 0"
  12. :touch="true"
  13. :interactive="true"
  14. placement="bottom-start"
  15. theme="search"
  16. ref="search"
  17. trigger="click"
  18. @show="
  19. () => {
  20. showFiltersDropdown = true;
  21. }
  22. "
  23. @hide="
  24. () => {
  25. showFiltersDropdown = false;
  26. }
  27. "
  28. >
  29. <div class="control has-addons" ref="trigger">
  30. <button class="button is-primary">
  31. <i class="material-icons icon-with-button"
  32. >filter_list</i
  33. >
  34. Filters
  35. </button>
  36. <button class="button">
  37. <i class="material-icons">
  38. {{
  39. showFiltersDropdown
  40. ? "expand_more"
  41. : "expand_less"
  42. }}
  43. </i>
  44. </button>
  45. </div>
  46. <template #content>
  47. <div class="control is-grouped input-with-button">
  48. <p class="control select is-expanded">
  49. <select v-model="addFilterValue">
  50. <option
  51. v-for="type in filters"
  52. :key="type.name"
  53. :value="type"
  54. >
  55. {{ type.displayName }}
  56. </option>
  57. </select>
  58. </p>
  59. <p class="control">
  60. <button
  61. :disabled="!addFilterValue"
  62. class="button material-icons is-success"
  63. @click="addFilterItem()"
  64. >
  65. control_point
  66. </button>
  67. </p>
  68. </div>
  69. <div
  70. v-for="(filter, index) in editingFilters"
  71. :key="`filter-${index}`"
  72. class="
  73. advanced-filter
  74. control
  75. is-grouped is-expanded
  76. "
  77. >
  78. <div class="control select">
  79. <select
  80. v-model="filter.filter"
  81. @change="changeFilterType(index)"
  82. >
  83. <option
  84. v-for="type in filters"
  85. :key="type.name"
  86. :value="type"
  87. >
  88. {{ type.displayName }}
  89. </option>
  90. </select>
  91. </div>
  92. <div class="control select">
  93. <select
  94. v-model="filter.filterType"
  95. :disabled="!filter.filterType"
  96. >
  97. <option
  98. v-for="filterType in filterTypes(
  99. filter.filter
  100. )"
  101. :key="filterType.name"
  102. :value="filterType.name"
  103. :selected="
  104. filter.filter
  105. .defaultFilterType ===
  106. filterType.name
  107. "
  108. >
  109. {{ filterType.displayName }}
  110. </option>
  111. </select>
  112. </div>
  113. <p class="control is-expanded">
  114. <input
  115. v-model="filter.data"
  116. class="input"
  117. type="text"
  118. placeholder="Search value"
  119. :disabled="!filter.filterType"
  120. @keydown.enter="applyFilterAndGetData()"
  121. />
  122. </p>
  123. <div class="control">
  124. <button
  125. class="button material-icons is-danger"
  126. @click="removeFilterItem(index)"
  127. >
  128. remove_circle_outline
  129. </button>
  130. </div>
  131. </div>
  132. <div
  133. v-if="editingFilters.length > 0"
  134. class="control is-expanded is-grouped"
  135. >
  136. <label class="control label"
  137. >Filter operator</label
  138. >
  139. <div class="control select is-expanded">
  140. <select v-model="filterOperator">
  141. <option
  142. v-for="operator in filterOperators"
  143. :key="operator.name"
  144. :value="operator.name"
  145. >
  146. {{ operator.displayName }}
  147. </option>
  148. </select>
  149. </div>
  150. </div>
  151. <div
  152. class="advanced-filter-bottom"
  153. v-if="editingFilters.length > 0"
  154. >
  155. <div class="control is-expanded">
  156. <button
  157. class="button is-info"
  158. @click="applyFilterAndGetData()"
  159. >
  160. <i
  161. class="
  162. material-icons
  163. icon-with-button
  164. "
  165. >filter_list</i
  166. >
  167. Apply filters
  168. </button>
  169. </div>
  170. </div>
  171. <div
  172. class="advanced-filter-bottom"
  173. v-else-if="editingFilters.length === 0"
  174. >
  175. <div class="control is-expanded">
  176. <button
  177. class="button is-info"
  178. @click="applyFilterAndGetData()"
  179. >
  180. <i
  181. class="
  182. material-icons
  183. icon-with-button
  184. "
  185. >filter_list</i
  186. >
  187. Apply filters
  188. </button>
  189. </div>
  190. </div>
  191. </template>
  192. </tippy>
  193. <tippy
  194. v-if="appliedFilters.length > 0"
  195. :touch="true"
  196. :interactive="true"
  197. theme="info"
  198. ref="activeFilters"
  199. >
  200. <div class="filters-indicator">
  201. {{ appliedFilters.length }}
  202. <i class="material-icons" @click.prevent="true"
  203. >filter_list</i
  204. >
  205. </div>
  206. <template #content>
  207. <p
  208. v-for="(filter, index) in appliedFilters"
  209. :key="`filter-${index}`"
  210. >
  211. {{ filter.filter.displayName }}
  212. {{
  213. appliedFilters.length === 1 &&
  214. appliedFilterOperator === "nor"
  215. ? "not"
  216. : ""
  217. }}
  218. {{ filter.filterType }} "{{ filter.data }}"
  219. {{
  220. appliedFilters.length === index + 1
  221. ? ""
  222. : appliedFilterOperator
  223. }}
  224. </p>
  225. </template>
  226. </tippy>
  227. <i
  228. v-else
  229. class="filters-indicator material-icons"
  230. content="No active filters"
  231. v-tippy="{ theme: 'info' }"
  232. >
  233. filter_list_off
  234. </i>
  235. </div>
  236. <div>
  237. <tippy
  238. v-if="hidableSortedColumns.length > 0"
  239. :touch="true"
  240. :interactive="true"
  241. placement="bottom-end"
  242. theme="dropdown"
  243. ref="editColumns"
  244. trigger="click"
  245. @show="
  246. () => {
  247. showColumnsDropdown = true;
  248. }
  249. "
  250. @hide="
  251. () => {
  252. showColumnsDropdown = false;
  253. }
  254. "
  255. >
  256. <div class="control has-addons" ref="trigger">
  257. <button class="button is-primary">
  258. <i class="material-icons icon-with-button"
  259. >tune</i
  260. >
  261. Columns
  262. </button>
  263. <button class="button">
  264. <i class="material-icons">
  265. {{
  266. showColumnsDropdown
  267. ? "expand_more"
  268. : "expand_less"
  269. }}
  270. </i>
  271. </button>
  272. </div>
  273. <template #content>
  274. <draggable
  275. item-key="name"
  276. v-model="orderedColumns"
  277. v-bind="columnDragOptions"
  278. tag="div"
  279. draggable=".item-draggable"
  280. class="nav-dropdown-items"
  281. @change="columnOrderChanged"
  282. >
  283. <template #item="{ element: column }">
  284. <button
  285. v-if="
  286. column.name !== 'select' &&
  287. column.name !== 'placeholder'
  288. "
  289. :class="{
  290. sortable: column.sortable,
  291. 'item-draggable': column.draggable,
  292. 'nav-item': true
  293. }"
  294. @click.prevent="
  295. toggleColumnVisibility(column)
  296. "
  297. >
  298. <p
  299. class="
  300. control
  301. is-expanded
  302. checkbox-control
  303. "
  304. >
  305. <label class="switch">
  306. <input
  307. type="checkbox"
  308. :id="index"
  309. :checked="
  310. shownColumns.indexOf(
  311. column.name
  312. ) !== -1
  313. "
  314. @click="
  315. toggleColumnVisibility(
  316. column
  317. )
  318. "
  319. />
  320. <span
  321. :class="{
  322. slider: true,
  323. round: true,
  324. disabled:
  325. !column.hidable
  326. }"
  327. ></span>
  328. </label>
  329. <label :for="index">
  330. <span></span>
  331. <p>{{ column.displayName }}</p>
  332. </label>
  333. </p>
  334. </button>
  335. </template>
  336. </draggable>
  337. </template>
  338. </tippy>
  339. </div>
  340. </div>
  341. <div class="table-container">
  342. <table
  343. :class="{
  344. table: true,
  345. 'has-checkboxes': hasCheckboxes
  346. }"
  347. >
  348. <thead>
  349. <draggable
  350. item-key="name"
  351. v-model="orderedColumns"
  352. v-bind="columnDragOptions"
  353. tag="tr"
  354. handle=".handle"
  355. draggable=".item-draggable"
  356. @change="columnOrderChanged"
  357. >
  358. <template #item="{ element: column }">
  359. <th
  360. v-if="
  361. !(
  362. column.name === 'select' &&
  363. data.length === 0
  364. ) &&
  365. shownColumns.indexOf(column.name) !== -1
  366. "
  367. :class="{
  368. sortable: column.sortable,
  369. 'item-draggable': column.draggable
  370. }"
  371. :style="{
  372. minWidth: Number.isNaN(column.minWidth)
  373. ? column.minWidth
  374. : `${column.minWidth}px`,
  375. width: Number.isNaN(column.width)
  376. ? column.width
  377. : `${column.width}px`,
  378. maxWidth: Number.isNaN(column.maxWidth)
  379. ? column.maxWidth
  380. : `${column.maxWidth}px`
  381. }"
  382. >
  383. <div v-if="column.name === 'select'">
  384. <p class="checkbox">
  385. <input
  386. type="checkbox"
  387. :checked="
  388. data.length ===
  389. selectedRows.length
  390. "
  391. @click="toggleAllRows()"
  392. />
  393. </p>
  394. </div>
  395. <div v-else class="handle">
  396. <span>
  397. {{ column.displayName }}
  398. </span>
  399. <span
  400. v-if="column.sortable"
  401. :content="`Sort by ${column.displayName}`"
  402. v-tippy
  403. >
  404. <span
  405. v-if="
  406. !sort[column.sortProperty]
  407. "
  408. class="material-icons"
  409. @click="changeSort(column)"
  410. >
  411. unfold_more
  412. </span>
  413. <span
  414. v-if="
  415. sort[
  416. column.sortProperty
  417. ] === 'ascending'
  418. "
  419. class="material-icons active"
  420. @click="changeSort(column)"
  421. >
  422. expand_more
  423. </span>
  424. <span
  425. v-if="
  426. sort[
  427. column.sortProperty
  428. ] === 'descending'
  429. "
  430. class="material-icons active"
  431. @click="changeSort(column)"
  432. >
  433. expand_less
  434. </span>
  435. </span>
  436. </div>
  437. <div
  438. class="resizer"
  439. v-if="column.resizable"
  440. @mousedown.prevent.stop="
  441. columnResizingStart(column, $event)
  442. "
  443. @touchstart.prevent.stop="
  444. columnResizingStart(column, $event)
  445. "
  446. @mouseup="columnResizingStop()"
  447. @touchend="columnResizingStop()"
  448. @dblclick="columnResetWidth(column)"
  449. ></div>
  450. </th>
  451. </template>
  452. </draggable>
  453. </thead>
  454. <tbody>
  455. <tr
  456. v-for="(item, itemIndex) in data"
  457. :key="item._id"
  458. :class="{
  459. selected: item.selected,
  460. highlighted: item.highlighted
  461. }"
  462. >
  463. <td
  464. v-for="column in sortedFilteredColumns"
  465. :key="`${item._id}-${column.name}`"
  466. >
  467. <slot
  468. :name="`column-${column.name}`"
  469. :item="item"
  470. v-if="
  471. column.properties.length === 0 ||
  472. column.properties.every(
  473. property =>
  474. item[property] !== undefined
  475. )
  476. "
  477. ></slot>
  478. <p
  479. class="checkbox"
  480. v-if="column.name === 'select'"
  481. >
  482. <input
  483. type="checkbox"
  484. :checked="item.selected"
  485. @click="
  486. toggleSelectedRow(itemIndex, $event)
  487. "
  488. />
  489. </p>
  490. <div
  491. class="resizer"
  492. v-if="column.resizable"
  493. @mousedown.prevent.stop="
  494. columnResizingStart(column, $event)
  495. "
  496. @touchstart.prevent.stop="
  497. columnResizingStart(column, $event)
  498. "
  499. @mouseup="columnResizingStop()"
  500. @touchend="columnResizingStop()"
  501. @dblclick="columnResetWidth(column)"
  502. ></div>
  503. </td>
  504. </tr>
  505. </tbody>
  506. </table>
  507. </div>
  508. <div class="table-footer">
  509. <div class="page-controls">
  510. <button
  511. :class="{ disabled: page === 1 }"
  512. class="button is-primary material-icons"
  513. :disabled="page === 1"
  514. @click="changePage(1)"
  515. content="First Page"
  516. v-tippy
  517. >
  518. skip_previous
  519. </button>
  520. <button
  521. :class="{ disabled: page === 1 }"
  522. class="button is-primary material-icons"
  523. :disabled="page === 1"
  524. @click="changePage(page - 1)"
  525. content="Previous Page"
  526. v-tippy
  527. >
  528. fast_rewind
  529. </button>
  530. <p>Page {{ page }} / {{ lastPage }}</p>
  531. <button
  532. :class="{ disabled: page === lastPage }"
  533. class="button is-primary material-icons"
  534. :disabled="page === lastPage"
  535. @click="changePage(page + 1)"
  536. content="Next Page"
  537. v-tippy
  538. >
  539. fast_forward
  540. </button>
  541. <button
  542. :class="{ disabled: page === lastPage }"
  543. class="button is-primary material-icons"
  544. :disabled="page === lastPage"
  545. @click="changePage(lastPage)"
  546. content="Last Page"
  547. v-tippy
  548. >
  549. skip_next
  550. </button>
  551. </div>
  552. <div class="page-size">
  553. <div class="control">
  554. <label class="label">Items per page</label>
  555. <p class="control select">
  556. <select
  557. v-model.number="pageSize"
  558. @change="changePageSize()"
  559. >
  560. <option value="10">10</option>
  561. <option value="25">25</option>
  562. <option value="50">50</option>
  563. <option value="100">100</option>
  564. <option value="250">250</option>
  565. <option value="500">500</option>
  566. <option value="1000">1000</option>
  567. </select>
  568. </p>
  569. </div>
  570. </div>
  571. </div>
  572. </div>
  573. <div
  574. v-if="hasCheckboxes && selectedRows.length > 0"
  575. class="bulk-popup"
  576. :style="{
  577. top: bulkPopup.top + 'px',
  578. left: bulkPopup.left + 'px'
  579. }"
  580. >
  581. <button
  582. class="button is-primary"
  583. :content="
  584. selectedRows.length === 1
  585. ? `${selectedRows.length} row selected`
  586. : `${selectedRows.length} rows selected`
  587. "
  588. v-tippy="{ theme: 'info' }"
  589. >
  590. {{ selectedRows.length }}
  591. </button>
  592. <slot name="bulk-actions" :item="selectedRows" />
  593. <div class="right">
  594. <slot name="bulk-actions-right" :item="selectedRows" />
  595. <span
  596. class="material-icons drag-icon"
  597. @mousedown.left="onDragBox"
  598. @touchstart="onDragBox"
  599. @dblclick="resetBulkActionsPosition()"
  600. >
  601. drag_indicator
  602. </span>
  603. </div>
  604. </div>
  605. </div>
  606. </template>
  607. <script>
  608. import { mapGetters } from "vuex";
  609. import draggable from "vuedraggable";
  610. import Toast from "toasters";
  611. import ws from "@/ws";
  612. export default {
  613. components: {
  614. draggable
  615. },
  616. props: {
  617. /*
  618. Column properties:
  619. name: Unique lowercase name
  620. displayName: Nice name for the column header
  621. properties: The properties this column needs to show data
  622. sortable: Boolean for whether the order of a particular column can be changed
  623. sortProperty: The property the backend will sort on if this column gets sorted, e.g. title
  624. hidable: Boolean for whether a column can be hidden
  625. defaultVisibility: Default visibility for a column, either "shown" or "hidden"
  626. draggable: Boolean for whether a column can be dragged/reordered,
  627. resizable: Boolean for whether a column can be resized
  628. minWidth: Minimum width of column, e.g. 50px
  629. width: Width of column, e.g. 100px
  630. maxWidth: Maximum width of column, e.g. 150px
  631. */
  632. columnDefault: { type: Object, default: () => {} },
  633. columns: { type: Array, default: null },
  634. filters: { type: Array, default: null },
  635. dataAction: { type: String, default: null },
  636. name: { type: String, default: null }
  637. },
  638. data() {
  639. return {
  640. page: 1,
  641. pageSize: 10,
  642. data: [],
  643. count: 0, // TODO Rename
  644. sort: {},
  645. orderedColumns: [],
  646. shownColumns: [],
  647. columnDragOptions() {
  648. return {
  649. animation: 200,
  650. group: "columns",
  651. disabled: false,
  652. ghostClass: "draggable-list-ghost",
  653. filter: ".ignore-elements",
  654. fallbackTolerance: 50
  655. };
  656. },
  657. editingFilters: [],
  658. appliedFilters: [],
  659. filterOperator: "or",
  660. appliedFilterOperator: "or",
  661. filterOperators: [
  662. {
  663. name: "or",
  664. displayName: "OR"
  665. },
  666. {
  667. name: "and",
  668. displayName: "AND"
  669. },
  670. {
  671. name: "nor",
  672. displayName: "NOR"
  673. }
  674. ],
  675. resizing: {},
  676. allFilterTypes: {
  677. contains: {
  678. name: "contains",
  679. displayName: "Contains"
  680. },
  681. exact: {
  682. name: "exact",
  683. displayName: "Exact"
  684. },
  685. regex: {
  686. name: "regex",
  687. displayName: "Regex"
  688. }
  689. },
  690. bulkPopup: {
  691. top: 0,
  692. left: 0,
  693. pos1: 0,
  694. pos2: 0,
  695. pos3: 0,
  696. pos4: 0
  697. },
  698. addFilterValue: null,
  699. showFiltersDropdown: false,
  700. showColumnsDropdown: false,
  701. lastColumnResizerTapped: null,
  702. lastColumnResizerTappedDate: 0,
  703. lastBulkActionsTappedDate: 0
  704. };
  705. },
  706. computed: {
  707. properties() {
  708. return Array.from(
  709. new Set(
  710. this.sortedFilteredColumns.flatMap(
  711. column => column.properties
  712. )
  713. )
  714. );
  715. },
  716. lastPage() {
  717. return Math.ceil(this.count / this.pageSize);
  718. },
  719. sortedFilteredColumns() {
  720. return this.orderedColumns.filter(
  721. column => this.shownColumns.indexOf(column.name) !== -1
  722. );
  723. },
  724. hidableSortedColumns() {
  725. return this.orderedColumns.filter(column => column.hidable);
  726. },
  727. lastSelectedItemIndex() {
  728. return this.data.findIndex(item => item.highlighted);
  729. },
  730. selectedRows() {
  731. return this.data.filter(data => data.selected);
  732. },
  733. hasCheckboxes() {
  734. return (
  735. this.$slots["bulk-actions"] != null ||
  736. this.$slots["bulk-actions-right"] != null
  737. );
  738. },
  739. ...mapGetters({
  740. socket: "websockets/getSocket"
  741. })
  742. },
  743. watch: {
  744. selectedRows(newSelectedRows, oldSelectedRows) {
  745. // If selected rows goes from zero to one or more selected, trigger onWindowResize, as otherwise the popup could be out of bounds
  746. if (oldSelectedRows.length === 0 && newSelectedRows.length > 0)
  747. this.onWindowResize();
  748. }
  749. },
  750. mounted() {
  751. const tableSettings = this.getTableSettings();
  752. this.orderedColumns = [
  753. {
  754. name: "select",
  755. displayName: "",
  756. properties: [],
  757. sortable: false,
  758. hidable: false,
  759. draggable: false,
  760. resizable: false,
  761. minWidth: 47,
  762. defaultWidth: 47,
  763. maxWidth: 47
  764. },
  765. ...this.columns.map(column => ({
  766. ...this.columnDefault,
  767. ...column
  768. })),
  769. {
  770. name: "placeholder",
  771. displayName: "",
  772. properties: [],
  773. sortable: false,
  774. hidable: false,
  775. draggable: false,
  776. resizable: false,
  777. minWidth: "auto",
  778. width: "auto",
  779. maxWidth: "auto"
  780. }
  781. ].sort((columnA, columnB) => {
  782. // Always places select column in the first position
  783. if (columnA.name === "select") return -1;
  784. // Always places placeholder column in the last position
  785. if (columnB.name === "placeholder") return -1;
  786. // If there are no table settings stored, use default ordering
  787. if (!tableSettings || !tableSettings.columnOrder) return 0;
  788. const indexA = tableSettings.columnOrder.indexOf(columnA.name);
  789. const indexB = tableSettings.columnOrder.indexOf(columnB.name);
  790. // If either of the columns is not stored in the table settings, use default ordering
  791. if (indexA === -1 || indexB === -1) return 0;
  792. return indexA - indexB;
  793. });
  794. this.shownColumns = this.orderedColumns
  795. .filter(column => {
  796. // If table settings exist, use shownColumns from settings to determine which columns to show
  797. if (tableSettings && tableSettings.shownColumns)
  798. return (
  799. tableSettings.shownColumns.indexOf(column.name) !== -1
  800. );
  801. // Table settings don't exist, only show if the default visibility isn't hidden
  802. return column.defaultVisibility !== "hidden";
  803. })
  804. .map(column => column.name);
  805. this.recalculateWidths();
  806. if (tableSettings) {
  807. // If table settings' pageSize is an integer, use it for the pageSize
  808. if (Number.isInteger(tableSettings?.pageSize))
  809. this.pageSize = tableSettings.pageSize;
  810. // If table settings' columnSort exists, sort all still existing columns based on table settings' columnSort object
  811. if (tableSettings.columnSort) {
  812. Object.entries(tableSettings.columnSort).forEach(
  813. ([columnName, sortDirection]) => {
  814. if (
  815. this.columns.find(
  816. column => column.name === columnName
  817. )
  818. )
  819. this.sort[columnName] = sortDirection;
  820. }
  821. );
  822. }
  823. // If table settings' columnWidths exists, load the stored widths into the columns
  824. if (tableSettings.columnWidths) {
  825. this.orderedColumns = this.orderedColumns.map(orderedColumn => {
  826. const columnWidth = tableSettings.columnWidths.find(
  827. column => column.name === orderedColumn.name
  828. )?.width;
  829. if (columnWidth)
  830. return { ...orderedColumn, width: columnWidth };
  831. return orderedColumn;
  832. });
  833. }
  834. if (
  835. tableSettings.filter &&
  836. tableSettings.filter.appliedFilters &&
  837. tableSettings.filter.appliedFilterOperator
  838. ) {
  839. const { appliedFilters, appliedFilterOperator } =
  840. tableSettings.filter;
  841. // Set the applied filter operator and filter operator to the value stored in table settings
  842. this.appliedFilterOperator = this.filterOperator =
  843. appliedFilterOperator;
  844. // Set the applied filters and editing filters to the value stored in table settings, for all filters that are allowed
  845. this.appliedFilters = appliedFilters.filter(appliedFilter =>
  846. this.filters.find(
  847. filter => appliedFilter.filter.name === filter.name
  848. )
  849. );
  850. this.editingFilters = appliedFilters.filter(appliedFilter =>
  851. this.filters.find(
  852. filter => appliedFilter.filter.name === filter.name
  853. )
  854. );
  855. }
  856. }
  857. this.resetBulkActionsPosition();
  858. this.$nextTick(() => {
  859. this.onWindowResize();
  860. window.addEventListener("resize", this.onWindowResize);
  861. });
  862. ws.onConnect(this.init);
  863. },
  864. unmounted() {
  865. window.removeEventListener("resize", this.onWindowResize);
  866. },
  867. methods: {
  868. init() {
  869. this.getData();
  870. },
  871. getData() {
  872. this.socket.dispatch(
  873. this.dataAction,
  874. this.page,
  875. this.pageSize,
  876. this.properties,
  877. this.sort,
  878. this.appliedFilters,
  879. this.appliedFilterOperator,
  880. res => {
  881. console.log(111, res);
  882. if (res.status === "success") {
  883. const { data, count } = res.data;
  884. this.data = data.map(row => ({
  885. ...row,
  886. selected: false
  887. }));
  888. this.count = count;
  889. } else {
  890. new Toast(res.message);
  891. }
  892. }
  893. );
  894. },
  895. changePageSize() {
  896. this.page = 1;
  897. this.getData();
  898. this.storeTableSettings();
  899. },
  900. changePage(page) {
  901. if (page < 1) return;
  902. if (page > this.lastPage) return;
  903. if (page === this.page) return;
  904. this.page = page;
  905. this.getData();
  906. },
  907. changeSort(column) {
  908. if (column.sortable) {
  909. const { sortProperty } = column;
  910. if (this.sort[sortProperty] === undefined)
  911. this.sort[sortProperty] = "ascending";
  912. else if (this.sort[sortProperty] === "ascending")
  913. this.sort[sortProperty] = "descending";
  914. else if (this.sort[sortProperty] === "descending")
  915. delete this.sort[sortProperty];
  916. this.getData();
  917. this.storeTableSettings();
  918. }
  919. },
  920. toggleColumnVisibility(column) {
  921. if (!column.hidable) return false;
  922. if (this.shownColumns.indexOf(column.name) !== -1) {
  923. if (this.shownColumns.length <= 3)
  924. return new Toast(
  925. `Unable to hide column ${column.displayName}, there must be at least 1 visibile column`
  926. );
  927. this.shownColumns.splice(
  928. this.shownColumns.indexOf(column.name),
  929. 1
  930. );
  931. } else {
  932. this.shownColumns.push(column.name);
  933. }
  934. this.recalculateWidths();
  935. this.getData();
  936. return this.storeTableSettings();
  937. },
  938. toggleSelectedRow(itemIndex, event) {
  939. const { shiftKey, ctrlKey } = event;
  940. // Shift was pressed, so attempt to select all items between the clicked item and last clicked item
  941. if (shiftKey) {
  942. // If the clicked item is already selected, prevent default, otherwise the checkbox will be unchecked
  943. if (this.data[itemIndex].selected) event.preventDefault();
  944. // If there is a last clicked item
  945. if (this.lastSelectedItemIndex >= 0) {
  946. // Clicked item is lower than last item, so select upwards until it reaches the last selected item
  947. if (itemIndex > this.lastSelectedItemIndex) {
  948. for (
  949. let itemIndexUp = itemIndex;
  950. itemIndexUp > this.lastSelectedItemIndex;
  951. itemIndexUp -= 1
  952. ) {
  953. this.data[itemIndexUp].selected = true;
  954. }
  955. }
  956. // Clicked item is higher than last item, so select downwards until it reaches the last selected item
  957. else if (itemIndex < this.lastSelectedItemIndex) {
  958. for (
  959. let itemIndexDown = itemIndex;
  960. itemIndexDown < this.lastSelectedItemIndex;
  961. itemIndexDown += 1
  962. ) {
  963. this.data[itemIndexDown].selected = true;
  964. }
  965. }
  966. }
  967. }
  968. // Ctrl was pressed, so attempt to unselect all items between the clicked item and last clicked item
  969. else if (ctrlKey) {
  970. // If the clicked item is already unselected, prevent default, otherwise the checkbox will be checked
  971. if (!this.data[itemIndex].selected) event.preventDefault();
  972. // If there is a last clicked item
  973. if (this.lastSelectedItemIndex >= 0) {
  974. // Clicked item is lower than last item, so unselect upwards until it reaches the last selected item
  975. if (itemIndex > this.lastSelectedItemIndex) {
  976. for (
  977. let itemIndexUp = itemIndex;
  978. itemIndexUp >= this.lastSelectedItemIndex;
  979. itemIndexUp -= 1
  980. ) {
  981. this.data[itemIndexUp].selected = false;
  982. }
  983. }
  984. // Clicked item is higher than last item, so unselect downwards until it reaches the last selected item
  985. else if (itemIndex < this.lastSelectedItemIndex) {
  986. for (
  987. let itemIndexDown = itemIndex;
  988. itemIndexDown <= this.lastSelectedItemIndex;
  989. itemIndexDown += 1
  990. ) {
  991. this.data[itemIndexDown].selected = false;
  992. }
  993. }
  994. }
  995. }
  996. // Neither ctrl nor shift were pressed, so toggle clicked item
  997. else {
  998. this.data[itemIndex].selected = !this.data[itemIndex].selected;
  999. }
  1000. // Set the last clicked item to no longer be highlighted, if it exists
  1001. if (this.lastSelectedItemIndex >= 0)
  1002. this.data[this.lastSelectedItemIndex].highlighted = false;
  1003. // Set the clicked item to be highlighted
  1004. this.data[itemIndex].highlighted = true;
  1005. },
  1006. toggleAllRows() {
  1007. if (this.data.length > this.selectedRows.length) {
  1008. this.data = this.data.map(row => ({ ...row, selected: true }));
  1009. } else {
  1010. this.data = this.data.map(row => ({ ...row, selected: false }));
  1011. }
  1012. },
  1013. addFilterItem() {
  1014. this.editingFilters.push({
  1015. data: "",
  1016. filter: this.addFilterValue,
  1017. filterType: this.addFilterValue.defaultFilterType
  1018. });
  1019. },
  1020. removeFilterItem(index) {
  1021. this.editingFilters.splice(index, 1);
  1022. },
  1023. columnResizingStart(column, event) {
  1024. const eventIsTouch = event.type === "touchstart";
  1025. if (eventIsTouch) {
  1026. // Handle double click from touch (if this method is called for the same column twice in a row within one second)
  1027. if (
  1028. this.lastColumnResizerTapped === column &&
  1029. Date.now() - this.lastColumnResizerTappedDate <= 1000
  1030. ) {
  1031. this.columnResetWidth(column);
  1032. this.lastColumnResizerTapped = null;
  1033. this.lastColumnResizerTappedDate = 0;
  1034. return;
  1035. }
  1036. this.lastColumnResizerTapped = column;
  1037. this.lastColumnResizerTappedDate = Date.now();
  1038. }
  1039. this.resizing.resizing = true;
  1040. this.resizing.resizingColumn = column;
  1041. this.resizing.width = event.target.parentElement.offsetWidth;
  1042. this.resizing.lastX = eventIsTouch
  1043. ? event.targetTouches[0].clientX
  1044. : event.x;
  1045. },
  1046. columnResizing(event) {
  1047. if (this.resizing.resizing) {
  1048. const eventIsTouch = event.type === "touchmove";
  1049. if (!eventIsTouch && event.buttons !== 1) {
  1050. this.resizing.resizing = false;
  1051. this.storeTableSettings();
  1052. }
  1053. const x = eventIsTouch
  1054. ? event.changedTouches[0].clientX
  1055. : event.x;
  1056. this.resizing.width -= this.resizing.lastX - x;
  1057. this.resizing.lastX = x;
  1058. if (
  1059. this.resizing.resizingColumn.minWidth &&
  1060. this.resizing.resizingColumn.maxWidth
  1061. ) {
  1062. this.resizing.resizingColumn.width = Math.max(
  1063. Math.min(
  1064. this.resizing.resizingColumn.maxWidth,
  1065. this.resizing.width
  1066. ),
  1067. this.resizing.resizingColumn.minWidth
  1068. );
  1069. } else if (this.resizing.resizingColumn.minWidth) {
  1070. this.resizing.resizingColumn.width = Math.max(
  1071. this.resizing.width,
  1072. this.resizing.resizingColumn.minWidth
  1073. );
  1074. } else if (this.resizing.resizingColumn.maxWidth) {
  1075. this.resizing.resizingColumn.width = Math.min(
  1076. this.resizing.resizingColumn.maxWidth,
  1077. this.resizing.width
  1078. );
  1079. } else {
  1080. this.resizing.resizingColumn.width = this.resizing.width;
  1081. }
  1082. this.resizing.width = this.resizing.resizingColumn.width;
  1083. console.log(`New width: ${this.resizing.width}px`);
  1084. this.storeTableSettings();
  1085. }
  1086. },
  1087. columnResizingStop() {
  1088. this.resizing.resizing = false;
  1089. this.storeTableSettings();
  1090. },
  1091. columnResetWidth(column) {
  1092. const index = this.orderedColumns.indexOf(column);
  1093. if (column.defaultWidth && !Number.isNaN(column.defaultWidth))
  1094. this.orderedColumns[index].width = column.defaultWidth;
  1095. else if (
  1096. column.calculatedWidth &&
  1097. !Number.isNaN(column.calculatedWidth)
  1098. )
  1099. this.orderedColumns[index].width = column.calculatedWidth;
  1100. this.storeTableSettings();
  1101. },
  1102. filterTypes(filter) {
  1103. if (!filter || !filter.filterTypes) return [];
  1104. return filter.filterTypes.map(
  1105. filterType => this.allFilterTypes[filterType]
  1106. );
  1107. },
  1108. changeFilterType(index) {
  1109. this.editingFilters[index].filterType =
  1110. this.editingFilters[index].filter.defaultFilterType;
  1111. },
  1112. onDragBox(e) {
  1113. const e1 = e || window.event;
  1114. const e1IsTouch = e1.type === "touchstart";
  1115. e1.preventDefault();
  1116. if (e1IsTouch) {
  1117. // Handle double click from touch (if this method is twice in a row within one second)
  1118. if (Date.now() - this.lastBulkActionsTappedDate <= 1000) {
  1119. this.resetBulkActionsPosition();
  1120. this.lastBulkActionsTappedDate = 0;
  1121. return;
  1122. }
  1123. this.lastBulkActionsTappedDate = Date.now();
  1124. }
  1125. this.bulkPopup.pos3 = e1IsTouch
  1126. ? e1.changedTouches[0].clientX
  1127. : e1.clientX;
  1128. this.bulkPopup.pos4 = e1IsTouch
  1129. ? e1.changedTouches[0].clientY
  1130. : e1.clientY;
  1131. document.onmousemove = document.ontouchmove = e => {
  1132. const e2 = e || window.event;
  1133. const e2IsTouch = e2.type === "touchmove";
  1134. if (!e2IsTouch) e2.preventDefault();
  1135. // Get the clientX and clientY
  1136. const e2ClientX = e2IsTouch
  1137. ? e2.changedTouches[0].clientX
  1138. : e2.clientX;
  1139. const e2ClientY = e2IsTouch
  1140. ? e2.changedTouches[0].clientY
  1141. : e2.clientY;
  1142. // calculate the new cursor position:
  1143. this.bulkPopup.pos1 = this.bulkPopup.pos3 - e2ClientX;
  1144. this.bulkPopup.pos2 = this.bulkPopup.pos4 - e2ClientY;
  1145. this.bulkPopup.pos3 = e2ClientX;
  1146. this.bulkPopup.pos4 = e2ClientY;
  1147. // set the element's new position:
  1148. this.bulkPopup.top -= this.bulkPopup.pos2;
  1149. this.bulkPopup.left -= this.bulkPopup.pos1;
  1150. if (this.bulkPopup.top < 0) this.bulkPopup.top = 0;
  1151. if (this.bulkPopup.top > document.body.clientHeight - 50)
  1152. this.bulkPopup.top = document.body.clientHeight - 50;
  1153. if (this.bulkPopup.left < 0) this.bulkPopup.left = 0;
  1154. if (this.bulkPopup.left > document.body.clientWidth - 400)
  1155. this.bulkPopup.left = document.body.clientWidth - 400;
  1156. };
  1157. document.onmouseup = document.ontouchend = () => {
  1158. document.onmouseup = null;
  1159. document.ontouchend = null;
  1160. document.onmousemove = null;
  1161. document.ontouchmove = null;
  1162. };
  1163. },
  1164. resetBulkActionsPosition() {
  1165. this.bulkPopup.top = document.body.clientHeight - 56;
  1166. this.bulkPopup.left = document.body.clientWidth / 2 - 200;
  1167. },
  1168. applyFilterAndGetData() {
  1169. this.appliedFilters = JSON.parse(
  1170. JSON.stringify(this.editingFilters)
  1171. );
  1172. this.appliedFilterOperator = this.filterOperator;
  1173. this.getData();
  1174. this.storeTableSettings();
  1175. },
  1176. recalculateWidths() {
  1177. let noWidthCount = 0;
  1178. let calculatedWidth = 0;
  1179. this.orderedColumns.forEach(column => {
  1180. if (
  1181. this.shownColumns.indexOf(column.name) !== -1 &&
  1182. (column.name !== "select" || this.hasCheckboxes)
  1183. )
  1184. if (
  1185. Number.isFinite(column.width) &&
  1186. !Number.isFinite(column.calculatedWidth)
  1187. ) {
  1188. calculatedWidth += column.width;
  1189. } else if (Number.isFinite(column.defaultWidth)) {
  1190. calculatedWidth += column.defaultWidth;
  1191. } else {
  1192. noWidthCount += 1;
  1193. }
  1194. });
  1195. calculatedWidth = Math.floor(
  1196. // max-width of table is 1880px
  1197. (Math.min(1880, document.body.clientWidth) - calculatedWidth) /
  1198. (noWidthCount - 1)
  1199. );
  1200. this.orderedColumns = this.orderedColumns.map(column => {
  1201. const orderedColumn = column;
  1202. if (this.shownColumns.indexOf(orderedColumn.name) !== -1) {
  1203. let newWidth;
  1204. if (Number.isFinite(orderedColumn.defaultWidth)) {
  1205. newWidth = orderedColumn.defaultWidth;
  1206. } else {
  1207. // eslint-disable-next-line no-param-reassign
  1208. newWidth = orderedColumn.calculatedWidth = Math.min(
  1209. Math.max(
  1210. orderedColumn.minWidth || 100, // fallback 100px min width
  1211. calculatedWidth
  1212. ),
  1213. orderedColumn.maxWidth || 1000 // fallback 1000px max width
  1214. );
  1215. }
  1216. if (newWidth && !Number.isFinite(orderedColumn.width))
  1217. orderedColumn.width = newWidth;
  1218. }
  1219. return orderedColumn;
  1220. });
  1221. },
  1222. columnOrderChanged() {
  1223. this.storeTableSettings();
  1224. },
  1225. getTableSettings() {
  1226. return JSON.parse(
  1227. localStorage.getItem(`advancedTableSettings:${this.name}`)
  1228. );
  1229. },
  1230. storeTableSettings() {
  1231. // Clear debounce timeout
  1232. if (this.storeTableSettingsDebounceTimeout)
  1233. clearTimeout(this.storeTableSettingsDebounceTimeout);
  1234. // Resizing calls this function a lot, so rather than saving dozens of times a second, use debouncing
  1235. this.storeTableSettingsDebounceTimeout = setTimeout(() => {
  1236. localStorage.setItem(
  1237. `advancedTableSettings:${this.name}`,
  1238. JSON.stringify({
  1239. pageSize: this.pageSize,
  1240. filter: {
  1241. appliedFilters: this.appliedFilters,
  1242. appliedFilterOperator: this.appliedFilterOperator
  1243. },
  1244. columnSort: this.sort,
  1245. columnOrder: this.orderedColumns.map(
  1246. column => column.name
  1247. ),
  1248. columnWidths: this.orderedColumns.map(column => ({
  1249. name: column.name,
  1250. width: column.width
  1251. })),
  1252. shownColumns: this.shownColumns
  1253. })
  1254. );
  1255. }, 250);
  1256. },
  1257. onWindowResize() {
  1258. // Only change the position if the popup is actually visible
  1259. if (this.selectedRows.length === 0) return;
  1260. if (this.bulkPopup.top < 0) this.bulkPopup.top = 0;
  1261. if (this.bulkPopup.top > document.body.clientHeight - 50)
  1262. this.bulkPopup.top = document.body.clientHeight - 50;
  1263. if (this.bulkPopup.left < 0) this.bulkPopup.left = 0;
  1264. if (this.bulkPopup.left > document.body.clientWidth - 400)
  1265. this.bulkPopup.left = document.body.clientWidth - 400;
  1266. }
  1267. }
  1268. };
  1269. </script>
  1270. <style lang="scss">
  1271. .table-container .table tbody td .row-options {
  1272. display: flex;
  1273. justify-content: space-between;
  1274. .icon-with-button {
  1275. height: 30px;
  1276. width: 30px;
  1277. }
  1278. }
  1279. .bulk-popup {
  1280. display: flex;
  1281. position: fixed;
  1282. flex-direction: row;
  1283. width: 100%;
  1284. max-width: 400px;
  1285. line-height: 36px;
  1286. z-index: 5;
  1287. border: 1px solid var(--light-grey-3);
  1288. border-radius: 5px;
  1289. box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
  1290. background-color: var(--white);
  1291. color: var(--dark-grey);
  1292. padding: 5px;
  1293. .right {
  1294. display: flex;
  1295. flex-direction: row;
  1296. margin-left: auto;
  1297. }
  1298. .drag-icon {
  1299. position: relative;
  1300. top: 6px;
  1301. color: var(--dark-grey);
  1302. cursor: move;
  1303. }
  1304. .bulk-actions {
  1305. display: flex;
  1306. flex-direction: row;
  1307. width: 100%;
  1308. justify-content: space-evenly;
  1309. .material-icons {
  1310. position: relative;
  1311. top: 6px;
  1312. margin-left: 5px;
  1313. cursor: pointer;
  1314. color: var(--primary-color);
  1315. &:hover,
  1316. &:focus {
  1317. filter: brightness(90%);
  1318. }
  1319. }
  1320. .delete-icon {
  1321. color: var(--dark-red);
  1322. }
  1323. }
  1324. }
  1325. </style>
  1326. <style lang="scss" scoped>
  1327. .night-mode {
  1328. .table-outer-container {
  1329. .table-container .table {
  1330. &,
  1331. thead th {
  1332. background-color: var(--dark-grey-3);
  1333. color: var(--light-grey-2);
  1334. }
  1335. tr {
  1336. th,
  1337. td {
  1338. border-color: var(--dark-grey) !important;
  1339. &:first-child {
  1340. background-color: var(--dark-grey-3) !important;
  1341. }
  1342. }
  1343. &:nth-child(even) {
  1344. &,
  1345. td:first-child {
  1346. background-color: var(--dark-grey-2) !important;
  1347. }
  1348. }
  1349. &:hover,
  1350. &:focus,
  1351. &.highlighted {
  1352. th,
  1353. td {
  1354. &,
  1355. &:first-child {
  1356. background-color: var(--dark-grey-4) !important;
  1357. }
  1358. }
  1359. }
  1360. }
  1361. }
  1362. .table-header,
  1363. .table-footer {
  1364. background-color: var(--dark-grey-3);
  1365. color: var(--light-grey-2);
  1366. }
  1367. .label.control {
  1368. background-color: var(--dark-grey) !important;
  1369. border-color: var(--grey-3) !important;
  1370. color: var(--white) !important;
  1371. }
  1372. }
  1373. .bulk-popup {
  1374. border: 0;
  1375. background-color: var(--dark-grey-2);
  1376. color: var(--white);
  1377. .material-icons {
  1378. color: var(--white);
  1379. }
  1380. }
  1381. }
  1382. .table-outer-container {
  1383. border-radius: 5px;
  1384. box-shadow: 0 2px 3px rgba(10, 10, 10, 0.1), 0 0 0 1px rgba(10, 10, 10, 0.1);
  1385. margin: 10px 0;
  1386. overflow: hidden;
  1387. .table-container {
  1388. overflow-x: auto;
  1389. table {
  1390. border-collapse: separate;
  1391. table-layout: fixed;
  1392. thead {
  1393. tr {
  1394. th {
  1395. height: 40px;
  1396. line-height: 40px;
  1397. border: 1px solid var(--light-grey-2);
  1398. border-width: 1px 1px 1px 0;
  1399. padding: 0;
  1400. &:last-child {
  1401. border-width: 1px 0 1px;
  1402. }
  1403. &.sortable {
  1404. cursor: pointer;
  1405. }
  1406. & > div {
  1407. display: flex;
  1408. white-space: nowrap;
  1409. padding: 8px 10px;
  1410. & > span {
  1411. margin-left: 5px;
  1412. &:first-child {
  1413. margin-left: 0;
  1414. margin-right: auto;
  1415. }
  1416. & > .material-icons {
  1417. font-size: 22px;
  1418. position: relative;
  1419. top: 6px;
  1420. cursor: pointer;
  1421. &.active {
  1422. color: var(--primary-color);
  1423. }
  1424. &:hover,
  1425. &:focus {
  1426. filter: brightness(90%);
  1427. }
  1428. }
  1429. }
  1430. }
  1431. }
  1432. }
  1433. }
  1434. tbody {
  1435. tr {
  1436. &.highlighted {
  1437. background-color: var(--light-grey);
  1438. }
  1439. td {
  1440. border: 1px solid var(--light-grey-2);
  1441. border-width: 0 1px 1px 0;
  1442. &:last-child {
  1443. border-width: 0 0 1px;
  1444. }
  1445. }
  1446. }
  1447. }
  1448. }
  1449. table {
  1450. thead tr,
  1451. tbody tr {
  1452. th,
  1453. td {
  1454. position: relative;
  1455. white-space: nowrap;
  1456. text-overflow: ellipsis;
  1457. overflow: hidden;
  1458. &:first-child {
  1459. display: none;
  1460. }
  1461. .resizer {
  1462. height: 100%;
  1463. width: 5px;
  1464. background-color: transparent;
  1465. cursor: col-resize;
  1466. position: absolute;
  1467. right: 0;
  1468. top: 0;
  1469. }
  1470. }
  1471. &:nth-child(even) td:first-child {
  1472. background-color: #fafafa;
  1473. }
  1474. &:hover,
  1475. &:focus,
  1476. &.highlighted {
  1477. th,
  1478. td {
  1479. &,
  1480. &:first-child {
  1481. background-color: var(--light-grey);
  1482. }
  1483. }
  1484. }
  1485. }
  1486. &.has-checkboxes {
  1487. thead tr,
  1488. tbody tr {
  1489. th,
  1490. td {
  1491. &:first-child {
  1492. display: table-cell;
  1493. position: sticky;
  1494. left: 0;
  1495. background-color: var(--white);
  1496. z-index: 2;
  1497. }
  1498. }
  1499. }
  1500. }
  1501. }
  1502. }
  1503. .table-header,
  1504. .table-footer {
  1505. display: flex;
  1506. flex-direction: row;
  1507. flex-wrap: wrap;
  1508. justify-content: space-between;
  1509. line-height: 36px;
  1510. background-color: var(--white);
  1511. }
  1512. .table-header > div {
  1513. display: flex;
  1514. flex-direction: row;
  1515. > span > .control {
  1516. margin: 5px;
  1517. }
  1518. .filters-indicator {
  1519. line-height: 46px;
  1520. display: flex;
  1521. align-items: center;
  1522. column-gap: 4px;
  1523. }
  1524. }
  1525. .table-footer {
  1526. .page-controls,
  1527. .page-size > .control {
  1528. display: flex;
  1529. flex-direction: row;
  1530. margin-bottom: 0 !important;
  1531. button {
  1532. margin: 5px;
  1533. font-size: 20px;
  1534. }
  1535. p,
  1536. label {
  1537. margin: 5px;
  1538. font-size: 14px;
  1539. font-weight: 600;
  1540. }
  1541. &.select::after {
  1542. top: 18px;
  1543. }
  1544. }
  1545. }
  1546. }
  1547. .control.is-grouped {
  1548. display: flex;
  1549. & > .control {
  1550. &.label {
  1551. height: 36px;
  1552. background-color: var(--white);
  1553. border: 1px solid var(--light-grey-2);
  1554. color: var(--dark-grey-2);
  1555. appearance: none;
  1556. border-radius: 3px;
  1557. font-size: 14px;
  1558. line-height: 34px;
  1559. padding-left: 8px;
  1560. padding-right: 8px;
  1561. }
  1562. &.select.is-expanded > select {
  1563. width: 100%;
  1564. }
  1565. & > input,
  1566. & > select,
  1567. & > .button,
  1568. &.label {
  1569. border-radius: 0;
  1570. }
  1571. &:first-child {
  1572. & > input,
  1573. & > select,
  1574. & > .button,
  1575. &.label {
  1576. border-radius: 5px 0 0 5px;
  1577. }
  1578. }
  1579. &:last-child {
  1580. & > input,
  1581. & > select,
  1582. & > .button,
  1583. &.label {
  1584. border-radius: 0 5px 5px 0;
  1585. }
  1586. }
  1587. & > .button {
  1588. font-size: 22px;
  1589. }
  1590. }
  1591. @media screen and (max-width: 500px) {
  1592. &.advanced-filter {
  1593. flex-wrap: wrap;
  1594. .control.select {
  1595. width: 50%;
  1596. select {
  1597. width: 100%;
  1598. }
  1599. }
  1600. .control {
  1601. margin-bottom: 0 !important;
  1602. &:nth-child(1) select {
  1603. border-radius: 5px 0 0 0;
  1604. }
  1605. &:nth-child(2) select {
  1606. border-radius: 0 5px 0 0;
  1607. }
  1608. &:nth-child(3) input {
  1609. border-radius: 0 0 0 5px;
  1610. }
  1611. &:nth-child(4) button {
  1612. border-radius: 0 0 5px 0;
  1613. }
  1614. }
  1615. }
  1616. }
  1617. }
  1618. .advanced-filter-bottom {
  1619. display: flex;
  1620. .button {
  1621. font-size: 16px !important;
  1622. width: 100%;
  1623. }
  1624. .control {
  1625. margin: 0 !important;
  1626. }
  1627. }
  1628. </style>