on 05-17-2016 1:50 PM
Hello All,
I have a sap.m. table.From that table am selecting few records based on some filter conditions and applying filters.
After filter condition am able to see the record count using iLength Property.
But my requirement is to get the filtered records and i need to download these records to excel.
Could any body please help me how to get the filtered records.
Hey Mantri,
Did you check this example?
You can change following lines of onDataExport event of the controller to filter which rows to export.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Mantri,
This is an example of downloading table contents as csv format, basicaly if you follow the code in the controller which downloads the data this is how its done.
When you click the upper right button "download" on the table view, this event is triggered on related controller.
You can adapt his easily to your scenario & table structure.
This piece of code indicates which rows of the table will be downloaded to your file.
If you want to download all the data you see without filtering, this is fine.
In your case, you want to download a filtered data so you can change the path above with your filtered item binding. This is just an example
So this should download the product(s) with the name 'Apple' into file, not the entire data on your table.
I hope this gives you an idea.
Regards
Ugur
Well, if this path should be same as your table's item binding path at the time when download is requested. You can set it dynamically by:
This should give you the filtered binding of your table.
Hey Mantri,
"table_id" should be the id of your table and the item binding should be set already when you want to do this. I would suggest you to download and modify that example I have sent you to have a better understanding. Furthermore, if you could post your codes, would be easier to help you out.
Regards
Ugur
HI,
in place of table_id i placed my table id.
I am sharing the code.
Please do suggest some changes to get only the filtered records.
var getlineFromValue | = sap.ui.getCore().byId("lineFromFilterId").mProperties.value; | ||
var getlineToValue | = sap.ui.getCore().byId("lineToFilterId").mProperties.value; | ||
var getMachineFromValue | = sap.ui.getCore().byId("machineFromFilterId").mProperties.value; | ||
var getMachineToValue | = sap.ui.getCore().byId("machineToFilterId").mProperties.value; | ||
var getSKUFromValue | = sap.ui.getCore().byId("skuFromFilterId").mProperties.value; | ||
var getSKUToValue | = sap.ui.getCore().byId("skuToFilterId").mProperties.value; | ||
var getDateFromValue | = sap.ui.getCore().byId("dateFrom").mProperties.value; | ||
var getDateToValue | = sap.ui.getCore().byId("dateTo").mProperties.value; | ||
debugger; | |||
var lineFilter | = new sap.ui.model.Filter({ | ||
path | : "line", | ||
operator : sap.ui.model.FilterOperator.BT, | |||
value1 : getlineFromValue, | |||
value2 : getlineToValue}); | |||
var machineFilter | = new sap.ui.model.Filter({ | ||
path | : "machine", | ||
operator : sap.ui.model.FilterOperator.BT, | |||
value1 : getMachineFromValue, | |||
value2 : getMachineToValue}); | |||
var skuFilter | = new sap.ui.model.Filter({ | ||
path | : "line", | ||
operator : sap.ui.model.FilterOperator.BT, | |||
value1 : getSKUFromValue, | |||
value2 : getSKUToValue}); | |||
var dateFilter | = new sap.ui.model.Filter({ | ||
path | : "line", | ||
operator : sap.ui.model.FilterOperator.BT, | |||
value1 : getDateFromValue, | |||
value2 : getDateToValue}); | |||
var finalFilter = new sap.ui.model.Filter({ | |||
filters :[ | |||
lineFilter, | |||
machineFilter, | |||
skuFilter, | |||
dateFilter, | |||
], | |||
or : true}); | |||
var selRecords = sap.ui.getCore().byId("RuleTableItems"); | |||
selRecords.getBinding("items").filter(finalFilter,sap.ui.model.FilterType.Application); | |||
this.getView().byId("("RuleTableItems");").getBinding("items"); |
}
Hey Mantri,
This synax is wrong, -> this.getView().byId("("RuleTableItems");").getBinding("items");
Should be var oBinding = this.getView().byId("RuleTableItems").getBinding("items");
console.log("item binding",oBinding); should let you see the binding on your console, but this is not really necessary, it will just give you an idea of what you have on your table.
Anyway, the code piece you have given is where you are filtering your table binding, i see. This should be working as you intended.
Lets say that you put a button on your screen to download those filtered entries from table according to the filtered binding of the table as you did. This button should trigger onDataExport event in your controller ( you should define this ) as given in the example, with minor differences. You should change the column names and binding according to your scenario.
You can give the path like this if you want to download the filtered data when the button is pressed.
....
....
...
...
You should prepare data format to be transferred to the file by giving the columns.
I hope that will give you an idea.
Regards
Ugur.
Hi Ugur,
This is my code to dowload data to excel.Please let me know if any changes need to be done.
I am able to download whole data.But i want to download only filtered data.Please let me know if any changes need to be done
var oExport = new sap.ui.core.util.Export({
exportType: new sap.ui.core.util.ExportTypeCSV({
separatorChar: " "
}),
models: oModel,
rows: {
//path: this.getView().byId("RuleTableItems").getBinding("items")
path : selRecords.getBinding("items").getPath()
},
columns: [
{
name: "Line",
template: {
content: {
path: "line"
}
}
},
{
name: "Machine",
template: {
content: {
path: "machine"
}
}
}
]
});
oExport.saveFile().always(function() {
this.destroy();
});
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.