williaster commented on a change in pull request #5707: [SIP-5] Refactor table
URL: 
https://github.com/apache/incubator-superset/pull/5707#discussion_r214225469
 
 

 ##########
 File path: superset/assets/src/visualizations/table.js
 ##########
 @@ -196,14 +221,82 @@ function tableVis(slice, payload) {
     sortBy = metrics[0];
   }
   if (sortBy) {
-    datatable.column(data.columns.indexOf(sortBy)).order(fd.order_desc ? 
'desc' : 'asc');
-  }
-  if (sortBy && metrics.indexOf(sortBy) < 0) {
-    // Hiding the sortBy column if not in the metrics list
-    datatable.column(data.columns.indexOf(sortBy)).visible(false);
+    const keys = columns.map(c => c.key);
+    const index = keys.indexOf(sortBy);
+    datatable.column(index).order(orderDesc ? 'desc' : 'asc');
+    if (metrics.indexOf(sortBy) < 0) {
+      // Hiding the sortBy column if not in the metrics list
+      datatable.column(index).visible(false);
+    }
   }
   datatable.draw();
-  container.parents('.widget').find('.tooltip').remove();
+  $container.parents('.widget').find('.tooltip').remove();
+}
+
+TableVis.propTypes = propTypes;
+
+function adaptor(slice, payload) {
+  const { selector, formData, datasource } = slice;
+  const {
+    align_pn: alignPn,
+    color_pn: colorPn,
+    include_search: includeSearch,
+    metrics,
+    order_desc: orderDesc,
+    page_length: pageLength,
+    percent_metrics: percentMetrics,
+    table_filter: tableFilter,
+    table_timestamp_format: tableTimestampFormat,
+    timeseries_limit_metric: timeseriesLimitMetric,
+  } = formData;
+  const {
+    verbose_map: verboseMap,
+    column_formats: columnFormats,
+  } = datasource;
+
+  const { records, columns } = payload.data;
+
+  const processedColumns = columns.map((key) => {
+    let label = verboseMap[key];
+    // Handle verbose names for percents
+    if (!label) {
+      if (key[0] === '%') {
+        const cleanedKey = key.substring(1);
+        label = '% ' + (verboseMap[cleanedKey] || cleanedKey);
+      } else {
+        label = key;
+      }
+    }
+    return {
+      key,
+      label,
+      format: columnFormats && columnFormats[key],
+    };
+  });
+
+  const element = document.querySelector(selector);
+
+  return TableVis(element, {
+    data: records,
+    height: slice.height(),
+    alignPn,
+    colorPn,
+    columns: processedColumns,
+    filters: slice.getFilters(),
+    includeSearch,
+    metrics,
+    onAddFilter(...args) { slice.addFilter(...args); },
+    orderDesc,
+    pageLength: pageLength && parseInt(pageLength, 10),
+    percentMetrics,
+    // Aug 22, 2018
+    // Perhaps this `tableFilter` field can be removed as there is
 
 Review comment:
   that's interesting. I think this table used to be able to function as a 
filter on dashboards but perhaps that broke at some point. @mistercrunch any 
thoughts?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to