util.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.getColumnKey = void 0;
  6. exports.getColumnPos = getColumnPos;
  7. exports.safeColumnTitle = exports.renderColumnTitle = void 0;
  8. const getColumnKey = (column, defaultKey) => {
  9. if ('key' in column && column.key !== undefined && column.key !== null) {
  10. return column.key;
  11. }
  12. if (column.dataIndex) {
  13. return Array.isArray(column.dataIndex) ? column.dataIndex.join('.') : column.dataIndex;
  14. }
  15. return defaultKey;
  16. };
  17. exports.getColumnKey = getColumnKey;
  18. function getColumnPos(index, pos) {
  19. return pos ? `${pos}-${index}` : `${index}`;
  20. }
  21. const renderColumnTitle = (title, props) => {
  22. if (typeof title === 'function') {
  23. return title(props);
  24. }
  25. return title;
  26. };
  27. /**
  28. * Safe get column title
  29. *
  30. * Should filter [object Object]
  31. *
  32. * @param title
  33. */
  34. exports.renderColumnTitle = renderColumnTitle;
  35. const safeColumnTitle = (title, props) => {
  36. const res = renderColumnTitle(title, props);
  37. if (Object.prototype.toString.call(res) === '[object Object]') {
  38. return '';
  39. }
  40. return res;
  41. };
  42. exports.safeColumnTitle = safeColumnTitle;