diff --git a/panoramix/forms.py b/panoramix/forms.py index b017f68076afd..9ebb0cd5236e9 100644 --- a/panoramix/forms.py +++ b/panoramix/forms.py @@ -326,6 +326,10 @@ def __init__(self, viz): "Range Filter", default=True, description=( "Whether to display the time range interactive selector")), + 'include_search': BetterBooleanField( + "Search Box", default=False, + description=( + "Whether to include a client side search box")), 'show_bubbles': BetterBooleanField( "Show Bubbles", default=False, description=( diff --git a/panoramix/static/widgets/viz_table.js b/panoramix/static/widgets/viz_table.js index 2272481b5e140..ac339aaad55ed 100644 --- a/panoramix/static/widgets/viz_table.js +++ b/panoramix/static/widgets/viz_table.js @@ -4,20 +4,56 @@ px.registerWidget('table', function(data_attribute) { var token = $('#' + token_name); function refresh(done) { - token.load(data_attribute.json_endpoint, function(response, status, xhr){ - if(status=="error"){ - var err = '
' + xhr.responseText + '
'; - token.html(err); - token.show(); - done(); + $.getJSON(data_attribute.json_endpoint, function(json){ + var data = json.data; + var metrics = json.form_data.metrics; + function col(c){ + arr = []; + for (var i=0; i 0) { + var main_metric = data_attribute.form_data.metrics[0]; + datatable.column(data.columns.indexOf(main_metric)).order( 'desc' ).draw(); + } + done(json); + }).fail(function(xhr){ + var err = '
' + xhr.responseText + '
'; + token.html(err); token.show(); done(); }); @@ -27,5 +63,4 @@ px.registerWidget('table', function(data_attribute) { render: refresh, resize: refresh, }; - }); diff --git a/panoramix/viz.py b/panoramix/viz.py index 667d9810f34af..f332cddf3bb08 100644 --- a/panoramix/viz.py +++ b/panoramix/viz.py @@ -242,7 +242,8 @@ class TableViz(BaseViz): 'fields': ( 'granularity', ('since', 'until'), - 'row_limit' + 'row_limit', + ('include_search', None), ) }, { @@ -261,16 +262,13 @@ class TableViz(BaseViz): css_files = ['lib/dataTables/dataTables.bootstrap.css'] is_timeseries = False js_files = [ + 'lib/d3.min.js', 'lib/dataTables/jquery.dataTables.min.js', 'lib/dataTables/dataTables.bootstrap.js', 'widgets/viz_table.js', ] css_files = ['widgets/viz_table.css'] - @property - def json_endpoint(self): - return self.get_url(async='true', standalone='true', skip_libs='true') - def query_obj(self): d = super(TableViz, self).query_obj() fd = self.form_data @@ -291,10 +289,15 @@ def get_df(self): self.form_data.get("granularity") == "all" and 'timestamp' in df): del df['timestamp'] - for m in self.metrics: - df[m + '__perc'] = np.rint((df[m] / np.max(df[m])) * 100) return df + def get_json_data(self): + df = self.get_df() + return dumps(dict( + records=df.to_dict(orient="records"), + columns=df.columns, + )) + class PivotTableViz(BaseViz): viz_type = "pivot_table"