util.js 821 B

1234567891011121314151617181920212223242526272829303132
  1. export const getColumnKey = (column, defaultKey) => {
  2. if ('key' in column && column.key !== undefined && column.key !== null) {
  3. return column.key;
  4. }
  5. if (column.dataIndex) {
  6. return Array.isArray(column.dataIndex) ? column.dataIndex.join('.') : column.dataIndex;
  7. }
  8. return defaultKey;
  9. };
  10. export function getColumnPos(index, pos) {
  11. return pos ? `${pos}-${index}` : `${index}`;
  12. }
  13. export const renderColumnTitle = (title, props) => {
  14. if (typeof title === 'function') {
  15. return title(props);
  16. }
  17. return title;
  18. };
  19. /**
  20. * Safe get column title
  21. *
  22. * Should filter [object Object]
  23. *
  24. * @param title
  25. */
  26. export const safeColumnTitle = (title, props) => {
  27. const res = renderColumnTitle(title, props);
  28. if (Object.prototype.toString.call(res) === '[object Object]') {
  29. return '';
  30. }
  31. return res;
  32. };