AdvancedTable.vue 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779
  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. maxWidth: { type: Number, default: 1880 }
  638. },
  639. data() {
  640. return {
  641. page: 1,
  642. pageSize: 10,
  643. data: [],
  644. count: 0, // TODO Rename
  645. sort: {},
  646. orderedColumns: [],
  647. shownColumns: [],
  648. columnDragOptions() {
  649. return {
  650. animation: 200,
  651. group: "columns",
  652. disabled: false,
  653. ghostClass: "draggable-list-ghost",
  654. filter: ".ignore-elements",
  655. fallbackTolerance: 50
  656. };
  657. },
  658. editingFilters: [],
  659. appliedFilters: [],
  660. filterOperator: "or",
  661. appliedFilterOperator: "or",
  662. filterOperators: [
  663. {
  664. name: "or",
  665. displayName: "OR"
  666. },
  667. {
  668. name: "and",
  669. displayName: "AND"
  670. },
  671. {
  672. name: "nor",
  673. displayName: "NOR"
  674. }
  675. ],
  676. resizing: {},
  677. allFilterTypes: {
  678. contains: {
  679. name: "contains",
  680. displayName: "Contains"
  681. },
  682. exact: {
  683. name: "exact",
  684. displayName: "Exact"
  685. },
  686. regex: {
  687. name: "regex",
  688. displayName: "Regex"
  689. }
  690. },
  691. bulkPopup: {
  692. top: 0,
  693. left: 0,
  694. pos1: 0,
  695. pos2: 0,
  696. pos3: 0,
  697. pos4: 0
  698. },
  699. addFilterValue: null,
  700. showFiltersDropdown: false,
  701. showColumnsDropdown: false,
  702. lastColumnResizerTapped: null,
  703. lastColumnResizerTappedDate: 0,
  704. lastBulkActionsTappedDate: 0
  705. };
  706. },
  707. computed: {
  708. properties() {
  709. return Array.from(
  710. new Set(
  711. this.sortedFilteredColumns.flatMap(
  712. column => column.properties
  713. )
  714. )
  715. );
  716. },
  717. lastPage() {
  718. return Math.ceil(this.count / this.pageSize);
  719. },
  720. sortedFilteredColumns() {
  721. return this.orderedColumns.filter(
  722. column => this.shownColumns.indexOf(column.name) !== -1
  723. );
  724. },
  725. hidableSortedColumns() {
  726. return this.orderedColumns.filter(column => column.hidable);
  727. },
  728. lastSelectedItemIndex() {
  729. return this.data.findIndex(item => item.highlighted);
  730. },
  731. selectedRows() {
  732. return this.data.filter(data => data.selected);
  733. },
  734. hasCheckboxes() {
  735. return (
  736. this.$slots["bulk-actions"] != null ||
  737. this.$slots["bulk-actions-right"] != null
  738. );
  739. },
  740. ...mapGetters({
  741. socket: "websockets/getSocket"
  742. })
  743. },
  744. watch: {
  745. selectedRows(newSelectedRows, oldSelectedRows) {
  746. // If selected rows goes from zero to one or more selected, trigger onWindowResize, as otherwise the popup could be out of bounds
  747. if (oldSelectedRows.length === 0 && newSelectedRows.length > 0)
  748. this.onWindowResize();
  749. }
  750. },
  751. mounted() {
  752. const tableSettings = this.getTableSettings();
  753. this.orderedColumns = [
  754. {
  755. name: "select",
  756. displayName: "",
  757. properties: [],
  758. sortable: false,
  759. hidable: false,
  760. draggable: false,
  761. resizable: false,
  762. minWidth: 47,
  763. defaultWidth: 47,
  764. maxWidth: 47
  765. },
  766. ...this.columns.map(column => ({
  767. ...this.columnDefault,
  768. ...column
  769. })),
  770. {
  771. name: "placeholder",
  772. displayName: "",
  773. properties: [],
  774. sortable: false,
  775. hidable: false,
  776. draggable: false,
  777. resizable: false,
  778. minWidth: "auto",
  779. width: "auto",
  780. maxWidth: "auto"
  781. }
  782. ].sort((columnA, columnB) => {
  783. // Always places select column in the first position
  784. if (columnA.name === "select") return -1;
  785. // Always places placeholder column in the last position
  786. if (columnB.name === "placeholder") return -1;
  787. // If there are no table settings stored, use default ordering
  788. if (!tableSettings || !tableSettings.columnOrder) return 0;
  789. const indexA = tableSettings.columnOrder.indexOf(columnA.name);
  790. const indexB = tableSettings.columnOrder.indexOf(columnB.name);
  791. // If either of the columns is not stored in the table settings, use default ordering
  792. if (indexA === -1 || indexB === -1) return 0;
  793. return indexA - indexB;
  794. });
  795. this.shownColumns = this.orderedColumns
  796. .filter(column => {
  797. // If table settings exist, use shownColumns from settings to determine which columns to show
  798. if (tableSettings && tableSettings.shownColumns)
  799. return (
  800. tableSettings.shownColumns.indexOf(column.name) !== -1
  801. );
  802. // Table settings don't exist, only show if the default visibility isn't hidden
  803. return column.defaultVisibility !== "hidden";
  804. })
  805. .map(column => column.name);
  806. this.recalculateWidths();
  807. if (tableSettings) {
  808. // If table settings' page is an integer, use it for the page
  809. if (Number.isInteger(tableSettings?.page))
  810. this.page = tableSettings.page;
  811. // If table settings' pageSize is an integer, use it for the pageSize
  812. if (Number.isInteger(tableSettings?.pageSize))
  813. this.pageSize = tableSettings.pageSize;
  814. // If table settings' columnSort exists, sort all still existing columns based on table settings' columnSort object
  815. if (tableSettings.columnSort) {
  816. Object.entries(tableSettings.columnSort).forEach(
  817. ([columnName, sortDirection]) => {
  818. if (
  819. this.columns.find(
  820. column => column.name === columnName
  821. )
  822. )
  823. this.sort[columnName] = sortDirection;
  824. }
  825. );
  826. }
  827. // If table settings' columnWidths exists, load the stored widths into the columns
  828. if (tableSettings.columnWidths) {
  829. this.orderedColumns = this.orderedColumns.map(orderedColumn => {
  830. const columnWidth = tableSettings.columnWidths.find(
  831. column => column.name === orderedColumn.name
  832. )?.width;
  833. if (columnWidth)
  834. return { ...orderedColumn, width: columnWidth };
  835. return orderedColumn;
  836. });
  837. }
  838. if (
  839. tableSettings.filter &&
  840. tableSettings.filter.appliedFilters &&
  841. tableSettings.filter.appliedFilterOperator
  842. ) {
  843. const { appliedFilters, appliedFilterOperator } =
  844. tableSettings.filter;
  845. // Set the applied filter operator and filter operator to the value stored in table settings
  846. this.appliedFilterOperator = this.filterOperator =
  847. appliedFilterOperator;
  848. // Set the applied filters and editing filters to the value stored in table settings, for all filters that are allowed
  849. this.appliedFilters = appliedFilters.filter(appliedFilter =>
  850. this.filters.find(
  851. filter => appliedFilter.filter.name === filter.name
  852. )
  853. );
  854. this.editingFilters = appliedFilters.filter(appliedFilter =>
  855. this.filters.find(
  856. filter => appliedFilter.filter.name === filter.name
  857. )
  858. );
  859. }
  860. }
  861. this.resetBulkActionsPosition();
  862. this.$nextTick(() => {
  863. this.onWindowResize();
  864. window.addEventListener("resize", this.onWindowResize);
  865. });
  866. ws.onConnect(this.init);
  867. },
  868. unmounted() {
  869. window.removeEventListener("resize", this.onWindowResize);
  870. if (this.storeTableSettingsDebounceTimeout)
  871. clearTimeout(this.storeTableSettingsDebounceTimeout);
  872. },
  873. methods: {
  874. init() {
  875. this.getData();
  876. this.setQuery();
  877. },
  878. getData() {
  879. this.socket.dispatch(
  880. this.dataAction,
  881. this.page,
  882. this.pageSize,
  883. this.properties,
  884. this.sort,
  885. this.appliedFilters,
  886. this.appliedFilterOperator,
  887. res => {
  888. console.log(111, res);
  889. if (res.status === "success") {
  890. const { data, count } = res.data;
  891. this.data = data.map(row => ({
  892. ...row,
  893. selected: false
  894. }));
  895. this.count = count;
  896. } else {
  897. new Toast(res.message);
  898. }
  899. }
  900. );
  901. },
  902. changePageSize() {
  903. this.page = 1;
  904. this.getData();
  905. this.storeTableSettings();
  906. },
  907. changePage(page) {
  908. if (page < 1) return;
  909. if (page > this.lastPage) return;
  910. if (page === this.page) return;
  911. this.page = page;
  912. this.getData();
  913. this.setQuery();
  914. },
  915. changeSort(column) {
  916. if (column.sortable) {
  917. const { sortProperty } = column;
  918. if (this.sort[sortProperty] === undefined)
  919. this.sort[sortProperty] = "ascending";
  920. else if (this.sort[sortProperty] === "ascending")
  921. this.sort[sortProperty] = "descending";
  922. else if (this.sort[sortProperty] === "descending")
  923. delete this.sort[sortProperty];
  924. this.getData();
  925. this.storeTableSettings();
  926. }
  927. },
  928. toggleColumnVisibility(column) {
  929. if (!column.hidable) return false;
  930. if (this.shownColumns.indexOf(column.name) !== -1) {
  931. if (this.shownColumns.length <= 3)
  932. return new Toast(
  933. `Unable to hide column ${column.displayName}, there must be at least 1 visibile column`
  934. );
  935. this.shownColumns.splice(
  936. this.shownColumns.indexOf(column.name),
  937. 1
  938. );
  939. } else {
  940. this.shownColumns.push(column.name);
  941. }
  942. this.recalculateWidths();
  943. this.getData();
  944. return this.storeTableSettings();
  945. },
  946. toggleSelectedRow(itemIndex, event) {
  947. const { shiftKey, ctrlKey } = event;
  948. // Shift was pressed, so attempt to select all items between the clicked item and last clicked item
  949. if (shiftKey) {
  950. // If the clicked item is already selected, prevent default, otherwise the checkbox will be unchecked
  951. if (this.data[itemIndex].selected) event.preventDefault();
  952. // If there is a last clicked item
  953. if (this.lastSelectedItemIndex >= 0) {
  954. // Clicked item is lower than last item, so select upwards until it reaches the last selected item
  955. if (itemIndex > this.lastSelectedItemIndex) {
  956. for (
  957. let itemIndexUp = itemIndex;
  958. itemIndexUp > this.lastSelectedItemIndex;
  959. itemIndexUp -= 1
  960. ) {
  961. this.data[itemIndexUp].selected = true;
  962. }
  963. }
  964. // Clicked item is higher than last item, so select downwards until it reaches the last selected item
  965. else if (itemIndex < this.lastSelectedItemIndex) {
  966. for (
  967. let itemIndexDown = itemIndex;
  968. itemIndexDown < this.lastSelectedItemIndex;
  969. itemIndexDown += 1
  970. ) {
  971. this.data[itemIndexDown].selected = true;
  972. }
  973. }
  974. }
  975. }
  976. // Ctrl was pressed, so attempt to unselect all items between the clicked item and last clicked item
  977. else if (ctrlKey) {
  978. // If the clicked item is already unselected, prevent default, otherwise the checkbox will be checked
  979. if (!this.data[itemIndex].selected) event.preventDefault();
  980. // If there is a last clicked item
  981. if (this.lastSelectedItemIndex >= 0) {
  982. // Clicked item is lower than last item, so unselect upwards until it reaches the last selected item
  983. if (itemIndex > this.lastSelectedItemIndex) {
  984. for (
  985. let itemIndexUp = itemIndex;
  986. itemIndexUp >= this.lastSelectedItemIndex;
  987. itemIndexUp -= 1
  988. ) {
  989. this.data[itemIndexUp].selected = false;
  990. }
  991. }
  992. // Clicked item is higher than last item, so unselect downwards until it reaches the last selected item
  993. else if (itemIndex < this.lastSelectedItemIndex) {
  994. for (
  995. let itemIndexDown = itemIndex;
  996. itemIndexDown <= this.lastSelectedItemIndex;
  997. itemIndexDown += 1
  998. ) {
  999. this.data[itemIndexDown].selected = false;
  1000. }
  1001. }
  1002. }
  1003. }
  1004. // Neither ctrl nor shift were pressed, so toggle clicked item
  1005. else {
  1006. this.data[itemIndex].selected = !this.data[itemIndex].selected;
  1007. }
  1008. // Set the last clicked item to no longer be highlighted, if it exists
  1009. if (this.lastSelectedItemIndex >= 0)
  1010. this.data[this.lastSelectedItemIndex].highlighted = false;
  1011. // Set the clicked item to be highlighted
  1012. this.data[itemIndex].highlighted = true;
  1013. },
  1014. toggleAllRows() {
  1015. if (this.data.length > this.selectedRows.length) {
  1016. this.data = this.data.map(row => ({ ...row, selected: true }));
  1017. } else {
  1018. this.data = this.data.map(row => ({ ...row, selected: false }));
  1019. }
  1020. },
  1021. addFilterItem() {
  1022. this.editingFilters.push({
  1023. data: "",
  1024. filter: this.addFilterValue,
  1025. filterType: this.addFilterValue.defaultFilterType
  1026. });
  1027. },
  1028. removeFilterItem(index) {
  1029. this.editingFilters.splice(index, 1);
  1030. },
  1031. columnResizingStart(column, event) {
  1032. const eventIsTouch = event.type === "touchstart";
  1033. if (eventIsTouch) {
  1034. // Handle double click from touch (if this method is called for the same column twice in a row within one second)
  1035. if (
  1036. this.lastColumnResizerTapped === column &&
  1037. Date.now() - this.lastColumnResizerTappedDate <= 1000
  1038. ) {
  1039. this.columnResetWidth(column);
  1040. this.lastColumnResizerTapped = null;
  1041. this.lastColumnResizerTappedDate = 0;
  1042. return;
  1043. }
  1044. this.lastColumnResizerTapped = column;
  1045. this.lastColumnResizerTappedDate = Date.now();
  1046. }
  1047. this.resizing.resizing = true;
  1048. this.resizing.resizingColumn = column;
  1049. this.resizing.width = event.target.parentElement.offsetWidth;
  1050. this.resizing.lastX = eventIsTouch
  1051. ? event.targetTouches[0].clientX
  1052. : event.x;
  1053. },
  1054. columnResizing(event) {
  1055. if (this.resizing.resizing) {
  1056. const eventIsTouch = event.type === "touchmove";
  1057. if (!eventIsTouch && event.buttons !== 1) {
  1058. this.resizing.resizing = false;
  1059. this.storeTableSettings();
  1060. }
  1061. const x = eventIsTouch
  1062. ? event.changedTouches[0].clientX
  1063. : event.x;
  1064. this.resizing.width -= this.resizing.lastX - x;
  1065. this.resizing.lastX = x;
  1066. if (
  1067. this.resizing.resizingColumn.minWidth &&
  1068. this.resizing.resizingColumn.maxWidth
  1069. ) {
  1070. this.resizing.resizingColumn.width = Math.max(
  1071. Math.min(
  1072. this.resizing.resizingColumn.maxWidth,
  1073. this.resizing.width
  1074. ),
  1075. this.resizing.resizingColumn.minWidth
  1076. );
  1077. } else if (this.resizing.resizingColumn.minWidth) {
  1078. this.resizing.resizingColumn.width = Math.max(
  1079. this.resizing.width,
  1080. this.resizing.resizingColumn.minWidth
  1081. );
  1082. } else if (this.resizing.resizingColumn.maxWidth) {
  1083. this.resizing.resizingColumn.width = Math.min(
  1084. this.resizing.resizingColumn.maxWidth,
  1085. this.resizing.width
  1086. );
  1087. } else {
  1088. this.resizing.resizingColumn.width = this.resizing.width;
  1089. }
  1090. this.resizing.width = this.resizing.resizingColumn.width;
  1091. console.log(`New width: ${this.resizing.width}px`);
  1092. this.storeTableSettings();
  1093. }
  1094. },
  1095. columnResizingStop() {
  1096. this.resizing.resizing = false;
  1097. this.storeTableSettings();
  1098. },
  1099. columnResetWidth(column) {
  1100. const index = this.orderedColumns.indexOf(column);
  1101. if (column.defaultWidth && !Number.isNaN(column.defaultWidth))
  1102. this.orderedColumns[index].width = column.defaultWidth;
  1103. else if (
  1104. column.calculatedWidth &&
  1105. !Number.isNaN(column.calculatedWidth)
  1106. )
  1107. this.orderedColumns[index].width = column.calculatedWidth;
  1108. this.storeTableSettings();
  1109. },
  1110. filterTypes(filter) {
  1111. if (!filter || !filter.filterTypes) return [];
  1112. return filter.filterTypes.map(
  1113. filterType => this.allFilterTypes[filterType]
  1114. );
  1115. },
  1116. changeFilterType(index) {
  1117. this.editingFilters[index].filterType =
  1118. this.editingFilters[index].filter.defaultFilterType;
  1119. },
  1120. onDragBox(e) {
  1121. const e1 = e || window.event;
  1122. const e1IsTouch = e1.type === "touchstart";
  1123. e1.preventDefault();
  1124. if (e1IsTouch) {
  1125. // Handle double click from touch (if this method is twice in a row within one second)
  1126. if (Date.now() - this.lastBulkActionsTappedDate <= 1000) {
  1127. this.resetBulkActionsPosition();
  1128. this.lastBulkActionsTappedDate = 0;
  1129. return;
  1130. }
  1131. this.lastBulkActionsTappedDate = Date.now();
  1132. }
  1133. this.bulkPopup.pos3 = e1IsTouch
  1134. ? e1.changedTouches[0].clientX
  1135. : e1.clientX;
  1136. this.bulkPopup.pos4 = e1IsTouch
  1137. ? e1.changedTouches[0].clientY
  1138. : e1.clientY;
  1139. document.onmousemove = document.ontouchmove = e => {
  1140. const e2 = e || window.event;
  1141. const e2IsTouch = e2.type === "touchmove";
  1142. if (!e2IsTouch) e2.preventDefault();
  1143. // Get the clientX and clientY
  1144. const e2ClientX = e2IsTouch
  1145. ? e2.changedTouches[0].clientX
  1146. : e2.clientX;
  1147. const e2ClientY = e2IsTouch
  1148. ? e2.changedTouches[0].clientY
  1149. : e2.clientY;
  1150. // calculate the new cursor position:
  1151. this.bulkPopup.pos1 = this.bulkPopup.pos3 - e2ClientX;
  1152. this.bulkPopup.pos2 = this.bulkPopup.pos4 - e2ClientY;
  1153. this.bulkPopup.pos3 = e2ClientX;
  1154. this.bulkPopup.pos4 = e2ClientY;
  1155. // set the element's new position:
  1156. this.bulkPopup.top -= this.bulkPopup.pos2;
  1157. this.bulkPopup.left -= this.bulkPopup.pos1;
  1158. if (this.bulkPopup.top < 0) this.bulkPopup.top = 0;
  1159. if (this.bulkPopup.top > document.body.clientHeight - 50)
  1160. this.bulkPopup.top = document.body.clientHeight - 50;
  1161. if (this.bulkPopup.left < 0) this.bulkPopup.left = 0;
  1162. if (this.bulkPopup.left > document.body.clientWidth - 400)
  1163. this.bulkPopup.left = document.body.clientWidth - 400;
  1164. };
  1165. document.onmouseup = document.ontouchend = () => {
  1166. document.onmouseup = null;
  1167. document.ontouchend = null;
  1168. document.onmousemove = null;
  1169. document.ontouchmove = null;
  1170. };
  1171. },
  1172. resetBulkActionsPosition() {
  1173. this.bulkPopup.top = document.body.clientHeight - 56;
  1174. this.bulkPopup.left = document.body.clientWidth / 2 - 200;
  1175. },
  1176. applyFilterAndGetData() {
  1177. this.appliedFilters = JSON.parse(
  1178. JSON.stringify(this.editingFilters)
  1179. );
  1180. this.appliedFilterOperator = this.filterOperator;
  1181. this.getData();
  1182. this.storeTableSettings();
  1183. },
  1184. recalculateWidths() {
  1185. let noWidthCount = 0;
  1186. let calculatedWidth = 0;
  1187. this.orderedColumns.forEach(column => {
  1188. if (
  1189. this.shownColumns.indexOf(column.name) !== -1 &&
  1190. (column.name !== "select" || this.hasCheckboxes)
  1191. )
  1192. if (
  1193. Number.isFinite(column.width) &&
  1194. !Number.isFinite(column.calculatedWidth)
  1195. ) {
  1196. calculatedWidth += column.width;
  1197. } else if (Number.isFinite(column.defaultWidth)) {
  1198. calculatedWidth += column.defaultWidth;
  1199. } else {
  1200. noWidthCount += 1;
  1201. }
  1202. });
  1203. calculatedWidth = Math.floor(
  1204. (Math.min(this.maxWidth, document.body.clientWidth) -
  1205. calculatedWidth) /
  1206. (noWidthCount - 1)
  1207. );
  1208. this.orderedColumns = this.orderedColumns.map(column => {
  1209. const orderedColumn = column;
  1210. if (this.shownColumns.indexOf(orderedColumn.name) !== -1) {
  1211. let newWidth;
  1212. if (Number.isFinite(orderedColumn.defaultWidth)) {
  1213. newWidth = orderedColumn.defaultWidth;
  1214. } else {
  1215. // eslint-disable-next-line no-param-reassign
  1216. newWidth = orderedColumn.calculatedWidth = Math.min(
  1217. Math.max(
  1218. orderedColumn.minWidth || 100, // fallback 100px min width
  1219. calculatedWidth
  1220. ),
  1221. orderedColumn.maxWidth || 1000 // fallback 1000px max width
  1222. );
  1223. }
  1224. if (newWidth && !Number.isFinite(orderedColumn.width))
  1225. orderedColumn.width = newWidth;
  1226. }
  1227. return orderedColumn;
  1228. });
  1229. },
  1230. columnOrderChanged() {
  1231. this.storeTableSettings();
  1232. },
  1233. getTableSettings() {
  1234. const urlTableSettings = {};
  1235. if (this.$route.query.page)
  1236. urlTableSettings.page = Number.parseInt(this.$route.query.page);
  1237. if (this.$route.query.pageSize)
  1238. urlTableSettings.pageSize = Number.parseInt(
  1239. this.$route.query.pageSize
  1240. );
  1241. if (this.$route.query.shownColumns)
  1242. urlTableSettings.shownColumns = JSON.parse(
  1243. this.$route.query.shownColumns
  1244. );
  1245. if (this.$route.query.columnOrder)
  1246. urlTableSettings.columnOrder = JSON.parse(
  1247. this.$route.query.columnOrder
  1248. );
  1249. if (this.$route.query.columnWidths)
  1250. urlTableSettings.columnWidths = JSON.parse(
  1251. this.$route.query.columnWidths
  1252. );
  1253. if (this.$route.query.columnSort)
  1254. urlTableSettings.columnSort = JSON.parse(
  1255. this.$route.query.columnSort
  1256. );
  1257. if (this.$route.query.filter)
  1258. urlTableSettings.filter = JSON.parse(this.$route.query.filter);
  1259. const localStorageTableSettings = JSON.parse(
  1260. localStorage.getItem(`advancedTableSettings:${this.name}`)
  1261. );
  1262. return {
  1263. ...localStorageTableSettings,
  1264. ...urlTableSettings
  1265. };
  1266. },
  1267. storeTableSettings() {
  1268. // Clear debounce timeout
  1269. if (this.storeTableSettingsDebounceTimeout)
  1270. clearTimeout(this.storeTableSettingsDebounceTimeout);
  1271. // Resizing calls this function a lot, so rather than saving dozens of times a second, use debouncing
  1272. this.storeTableSettingsDebounceTimeout = setTimeout(() => {
  1273. this.setQuery();
  1274. this.setLocalStorage();
  1275. }, 250);
  1276. },
  1277. setQuery() {
  1278. const queryObject = {
  1279. ...this.$route.query,
  1280. page: this.page,
  1281. pageSize: this.pageSize,
  1282. filter: JSON.stringify({
  1283. appliedFilters: this.appliedFilters,
  1284. appliedFilterOperator: this.appliedFilterOperator
  1285. }),
  1286. columnSort: JSON.stringify(this.sort),
  1287. columnOrder: JSON.stringify(
  1288. this.orderedColumns.map(column => column.name)
  1289. ),
  1290. columnWidths: JSON.stringify(
  1291. this.orderedColumns.map(column => ({
  1292. name: column.name,
  1293. width: column.width
  1294. }))
  1295. ),
  1296. shownColumns: JSON.stringify(this.shownColumns)
  1297. };
  1298. const queryString = `?${Object.keys(queryObject)
  1299. .map(key => `${key}=${queryObject[key]}`)
  1300. .join("&")}`;
  1301. window.history.replaceState(null, null, queryString);
  1302. },
  1303. setLocalStorage() {
  1304. localStorage.setItem(
  1305. `advancedTableSettings:${this.name}`,
  1306. JSON.stringify({
  1307. pageSize: this.pageSize,
  1308. filter: {
  1309. appliedFilters: this.appliedFilters,
  1310. appliedFilterOperator: this.appliedFilterOperator
  1311. },
  1312. columnSort: this.sort,
  1313. columnOrder: this.orderedColumns.map(column => column.name),
  1314. columnWidths: this.orderedColumns.map(column => ({
  1315. name: column.name,
  1316. width: column.width
  1317. })),
  1318. shownColumns: this.shownColumns
  1319. })
  1320. );
  1321. },
  1322. onWindowResize() {
  1323. // Only change the position if the popup is actually visible
  1324. if (this.selectedRows.length === 0) return;
  1325. if (this.bulkPopup.top < 0) this.bulkPopup.top = 0;
  1326. if (this.bulkPopup.top > document.body.clientHeight - 50)
  1327. this.bulkPopup.top = document.body.clientHeight - 50;
  1328. if (this.bulkPopup.left < 0) this.bulkPopup.left = 0;
  1329. if (this.bulkPopup.left > document.body.clientWidth - 400)
  1330. this.bulkPopup.left = document.body.clientWidth - 400;
  1331. }
  1332. }
  1333. };
  1334. </script>
  1335. <style lang="scss" scoped>
  1336. .night-mode {
  1337. .table-outer-container {
  1338. .table-container .table {
  1339. &,
  1340. thead th {
  1341. background-color: var(--dark-grey-3);
  1342. color: var(--light-grey-2);
  1343. }
  1344. tr {
  1345. th,
  1346. td {
  1347. border-color: var(--dark-grey) !important;
  1348. &:first-child {
  1349. background-color: var(--dark-grey-3) !important;
  1350. }
  1351. }
  1352. &:nth-child(even) {
  1353. &,
  1354. td:first-child {
  1355. background-color: var(--dark-grey-2) !important;
  1356. }
  1357. }
  1358. &:hover,
  1359. &:focus,
  1360. &.highlighted {
  1361. th,
  1362. td {
  1363. &,
  1364. &:first-child {
  1365. background-color: var(--dark-grey-4) !important;
  1366. }
  1367. }
  1368. }
  1369. }
  1370. }
  1371. .table-header,
  1372. .table-footer {
  1373. background-color: var(--dark-grey-3);
  1374. color: var(--light-grey-2);
  1375. }
  1376. .label.control {
  1377. background-color: var(--dark-grey) !important;
  1378. border-color: var(--grey-3) !important;
  1379. color: var(--white) !important;
  1380. }
  1381. }
  1382. .bulk-popup {
  1383. border: 0;
  1384. background-color: var(--dark-grey-2);
  1385. color: var(--white);
  1386. .material-icons {
  1387. color: var(--white);
  1388. }
  1389. }
  1390. }
  1391. .table-outer-container {
  1392. border-radius: 5px;
  1393. box-shadow: 0 2px 3px rgba(10, 10, 10, 0.1), 0 0 0 1px rgba(10, 10, 10, 0.1);
  1394. margin: 10px 0;
  1395. overflow: hidden;
  1396. .table-container {
  1397. overflow-x: auto;
  1398. table {
  1399. border-collapse: separate;
  1400. table-layout: fixed;
  1401. thead {
  1402. tr {
  1403. th {
  1404. height: 40px;
  1405. line-height: 40px;
  1406. border: 1px solid var(--light-grey-2);
  1407. border-width: 1px 1px 1px 0;
  1408. padding: 0;
  1409. &:last-child {
  1410. border-width: 1px 0 1px;
  1411. }
  1412. &.sortable {
  1413. cursor: pointer;
  1414. }
  1415. & > div {
  1416. display: flex;
  1417. white-space: nowrap;
  1418. padding: 8px 10px;
  1419. & > span {
  1420. margin-left: 5px;
  1421. &:first-child {
  1422. margin-left: 0;
  1423. margin-right: auto;
  1424. }
  1425. & > .material-icons {
  1426. font-size: 22px;
  1427. position: relative;
  1428. top: 6px;
  1429. cursor: pointer;
  1430. &.active {
  1431. color: var(--primary-color);
  1432. }
  1433. &:hover,
  1434. &:focus {
  1435. filter: brightness(90%);
  1436. }
  1437. }
  1438. }
  1439. }
  1440. }
  1441. }
  1442. }
  1443. tbody {
  1444. tr {
  1445. &.highlighted {
  1446. background-color: var(--light-grey);
  1447. }
  1448. td {
  1449. border: 1px solid var(--light-grey-2);
  1450. border-width: 0 1px 1px 0;
  1451. &:last-child {
  1452. border-width: 0 0 1px;
  1453. }
  1454. /deep/ .row-options {
  1455. display: flex;
  1456. justify-content: space-between;
  1457. .icon-with-button {
  1458. height: 30px;
  1459. width: 30px;
  1460. }
  1461. }
  1462. }
  1463. }
  1464. }
  1465. }
  1466. table {
  1467. thead tr,
  1468. tbody tr {
  1469. th,
  1470. td {
  1471. position: relative;
  1472. white-space: nowrap;
  1473. text-overflow: ellipsis;
  1474. overflow: hidden;
  1475. &:first-child {
  1476. display: none;
  1477. }
  1478. .resizer {
  1479. height: 100%;
  1480. width: 5px;
  1481. background-color: transparent;
  1482. cursor: col-resize;
  1483. position: absolute;
  1484. right: 0;
  1485. top: 0;
  1486. }
  1487. }
  1488. &:nth-child(even) td:first-child {
  1489. background-color: #fafafa;
  1490. }
  1491. &:hover,
  1492. &:focus,
  1493. &.highlighted {
  1494. th,
  1495. td {
  1496. &,
  1497. &:first-child {
  1498. background-color: var(--light-grey);
  1499. }
  1500. }
  1501. }
  1502. }
  1503. &.has-checkboxes {
  1504. thead tr,
  1505. tbody tr {
  1506. th,
  1507. td {
  1508. &:first-child {
  1509. display: table-cell;
  1510. position: sticky;
  1511. left: 0;
  1512. background-color: var(--white);
  1513. z-index: 2;
  1514. }
  1515. }
  1516. }
  1517. }
  1518. }
  1519. }
  1520. .table-header,
  1521. .table-footer {
  1522. display: flex;
  1523. flex-direction: row;
  1524. flex-wrap: wrap;
  1525. justify-content: space-between;
  1526. line-height: 36px;
  1527. background-color: var(--white);
  1528. }
  1529. .table-header > div {
  1530. display: flex;
  1531. flex-direction: row;
  1532. > span > .control {
  1533. margin: 5px;
  1534. }
  1535. .filters-indicator {
  1536. line-height: 46px;
  1537. display: flex;
  1538. align-items: center;
  1539. column-gap: 4px;
  1540. }
  1541. }
  1542. .table-footer {
  1543. .page-controls,
  1544. .page-size > .control {
  1545. display: flex;
  1546. flex-direction: row;
  1547. margin-bottom: 0 !important;
  1548. button {
  1549. margin: 5px;
  1550. font-size: 20px;
  1551. }
  1552. p,
  1553. label {
  1554. margin: 5px;
  1555. font-size: 14px;
  1556. font-weight: 600;
  1557. }
  1558. &.select::after {
  1559. top: 18px;
  1560. }
  1561. }
  1562. }
  1563. }
  1564. .control.is-grouped {
  1565. display: flex;
  1566. & > .control {
  1567. &.label {
  1568. height: 36px;
  1569. background-color: var(--white);
  1570. border: 1px solid var(--light-grey-2);
  1571. color: var(--dark-grey-2);
  1572. appearance: none;
  1573. border-radius: 3px;
  1574. font-size: 14px;
  1575. line-height: 34px;
  1576. padding-left: 8px;
  1577. padding-right: 8px;
  1578. }
  1579. &.select.is-expanded > select {
  1580. width: 100%;
  1581. }
  1582. & > input,
  1583. & > select,
  1584. & > .button,
  1585. &.label {
  1586. border-radius: 0;
  1587. }
  1588. &:first-child {
  1589. & > input,
  1590. & > select,
  1591. & > .button,
  1592. &.label {
  1593. border-radius: 5px 0 0 5px;
  1594. }
  1595. }
  1596. &:last-child {
  1597. & > input,
  1598. & > select,
  1599. & > .button,
  1600. &.label {
  1601. border-radius: 0 5px 5px 0;
  1602. }
  1603. }
  1604. & > .button {
  1605. font-size: 22px;
  1606. }
  1607. }
  1608. @media screen and (max-width: 500px) {
  1609. &.advanced-filter {
  1610. flex-wrap: wrap;
  1611. .control.select {
  1612. width: 50%;
  1613. select {
  1614. width: 100%;
  1615. }
  1616. }
  1617. .control {
  1618. margin-bottom: 0 !important;
  1619. &:nth-child(1) select {
  1620. border-radius: 5px 0 0 0;
  1621. }
  1622. &:nth-child(2) select {
  1623. border-radius: 0 5px 0 0;
  1624. }
  1625. &:nth-child(3) input {
  1626. border-radius: 0 0 0 5px;
  1627. }
  1628. &:nth-child(4) button {
  1629. border-radius: 0 0 5px 0;
  1630. }
  1631. }
  1632. }
  1633. }
  1634. }
  1635. .advanced-filter-bottom {
  1636. display: flex;
  1637. .button {
  1638. font-size: 16px !important;
  1639. width: 100%;
  1640. }
  1641. .control {
  1642. margin: 0 !important;
  1643. }
  1644. }
  1645. /deep/ .bulk-popup {
  1646. display: flex;
  1647. position: fixed;
  1648. flex-direction: row;
  1649. width: 100%;
  1650. max-width: 400px;
  1651. line-height: 36px;
  1652. z-index: 5;
  1653. border: 1px solid var(--light-grey-3);
  1654. border-radius: 5px;
  1655. box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
  1656. background-color: var(--white);
  1657. color: var(--dark-grey);
  1658. padding: 5px;
  1659. .right {
  1660. display: flex;
  1661. flex-direction: row;
  1662. margin-left: auto;
  1663. }
  1664. .drag-icon {
  1665. position: relative;
  1666. top: 6px;
  1667. color: var(--dark-grey);
  1668. cursor: move;
  1669. }
  1670. .bulk-actions {
  1671. display: flex;
  1672. flex-direction: row;
  1673. width: 100%;
  1674. justify-content: space-evenly;
  1675. .material-icons {
  1676. position: relative;
  1677. top: 6px;
  1678. margin-left: 5px;
  1679. cursor: pointer;
  1680. color: var(--primary-color);
  1681. &:hover,
  1682. &:focus {
  1683. filter: brightness(90%);
  1684. }
  1685. }
  1686. .delete-icon {
  1687. color: var(--dark-red);
  1688. }
  1689. }
  1690. }
  1691. </style>