Filters in SAPUI5 viz

怎甘沉沦 提交于 2021-01-24 15:45:14

问题


I am trying to display a result det data on a table and a chart together. For exampIe: A user gives a value as an input and a query has to be made to the server to filter the table based on the user input and give nbacj the result set.

I am implementing a filter on the table and then bind the filtered result set to the table. I write the below code which works fine.

var oModel = new sap.ui.model.odata.ODataModel( "../TEST_ODATA.xsodata",false);  
oTable.setModel(oModel);  
var oFilter=new sap.ui.model.Filter("SUPPLIERID",sap.ui.model.FilterOperator.EQ,oInput1.getValue());  
oTable.getBinding("rows").filter(oFilter);  
var NumberOfRows = oTable.getBinding("rows").iLength;  
oTable.setTitle("Title1" + "(" + NumberOfRows + ")");  
oTable.placeAt("content");

Now I need to bind ofilter to a chart too and I write the following code which does not work.

var oDataset = new sap.viz.ui5.data.FlattenedDataset({  
    dimensions : [{axis : 1, name : 'SUPPLIERID', value : "{SUPPLIERID}"},{axis : 2, name : 'MATERIALNUMBER', value : "{MATERIALNUMBER}"}],  
    measures : [{name : 'Result', value : '{Result}'}],  
    data : {  
  path : "/service_path"  
  }});  

var oStackChart = new sap.viz.ui5.StackedColumn({  
  width : "80%",  
  height : "400px",  
  plotArea : {'colorPalette' : d3.scale.category20().range()},  
  title : {visible : true,text : 'Title2'},  
  dataset : oDataset});  

oStackChart.setModel(oModel);  
var oFilter=new sap.ui.model.Filter("SUPPLIERID",sap.ui.model.FilterOperator.EQ,oInput1.getValue());  
oStackChart.getBinding("rows").filter(oFilter);  
oStackChart.placeAt("content");  

Can anyone suggest the change in my code to do so. Kindly help.

Thanks


回答1:


You can add the filters to the FlattenedDataset like:

var oDataset = new FlattenedDataset({ // required by "sap/viz/ui5/data/FlattenedDataset"
  dimensions: aDimensions,
  measures: aMeasures,
  data: {
    path: sEntity,
    filters: [ oFilter ],
    parameters: {
      select: 'ProductID,UnitPrice,Quantity'
    }
  }
});

Note I used parameters to reduce the columns returned.



来源:https://stackoverflow.com/questions/21931561/filters-in-sapui5-viz

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!