on 12-24-2014 6:25 AM
hi experts,
i'm unable to figure out the best way to get all the selected rows using checked boxes. and use them to call a odata create service.
i'm thinking of like this:
1. create an empty js var > onselect of check box > push the selected row (with all column values) into js var
2. wn use click on submit button, use submitbatch function to push all the data into service.
is this proper way of doing? or any better way to get the selected values using api and use them to submit batch?
Not sure i understood correctly. If you are thinking to initialize certain values or variables, no need to call the init() method. Instead you can have a function globally and call it in init() and in your checkbox action, which resets the required thing.
If you still want to reload, may be you can try window.location.reload();
Cheers,
Meganadhan S
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks Meganadhan for your reply.
let me explain little in detail:
1#
i've a sap.ui.table with check boxes as first column. user would come in and check more than one check boxes in the table and clicks on submit.
2#
on submit i need call createBatchOperation + submitBatch() or just create()
3#
the above action will update another table in the backend not the same table as in step#1
4#
so in plan terms, user will come and select few rows from table1 and submits (oData.create() or oData.submitBatch() call) and goto another view see the values in table2 (oData.read()) that he submitted
5#
imp thing: as the columns of both the tables are not same, so i need below:
- how to collect all the rows selected by user and submit them when they click on submit button
- when i form a javascript array (with json format) i want to submit to oData.create() or oData.submitBatch()
- is this correct approach or any better way of doing
- rite now i'm stuck up on collecting the rows selected via check boxes.
appreciate if you guide me a little on the approach.
hi Dennis,
it was very helpful and very close, but i've below things.. which is not allowing in my application:
1- i'm using var path = oEvent.getSource().getBindingContext().getPath(); instead of
var path = this.getBindingContext().getPath(); so clear here
2- but console.log(path): returns me like '/MyEntitySet(param1='val1',param2='val2')', so due to this idx would return 'NaN' 😞 . but no worries here too, i've reusable function which can give me the id/index of the selected row. guess its sufficient
3- Uncaught TypeError: undefined is not a function:
it comes at var m = this.getModel('selection'); same issue as point#1. as 'this' is not being recognized here. i've replaced it with oEvent.getSource() for points #2 & #3
4- Uncaught TypeError: Cannot read property '3' of undefined
it comes at selectedItems.push(m[x]);
my modified code:
var sel = oTable.getModel('selection').getData();
var selectedItems = [];
var m = oTable.getModel().getProperty('/MyEntitySet');
Object.getOwnPropertyNames(sel).forEach(function(x) {
selectedItems.push(m[x]); //error here
});;
sap.m.MessageToast.show(JSON.stringify(selectedItems));
is this due to the structure of oData response (response data) model??
Hi
Maybe we want to try another way.
(look for // change, places where I have made changes w.r.t. previous example)
-D
hi Dennis,
as said, your earlier jsbin approach was near to my requirement.. i've made it finally.. ya with lots of code changes and logic. and thanks for the changed jsbin .. which takes the array.. thanks again.
so what i'm doing is forming a required key during onCheck and using it to get the row-data by passing it onto oModel.getProperty()...and processing it further..!
User | Count |
---|---|
84 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.