cancel
Showing results for 
Search instead for 
Did you mean: 

get selected rows using checked-box in sap.ui.table

Former Member
0 Kudos

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?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

PMarti
Active Participant
0 Kudos

Hi SAP Box,

I show you an example that may help you: JS Bin - Example

Regards,

Pau

Former Member
0 Kudos

thanks Pau. but i use sap.ui.table!

former_member182862
Active Contributor
0 Kudos

Hi "SAP Box"

This is what you looking for ?

Example

-D

Former Member
0 Kudos

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??

former_member182862
Active Contributor
0 Kudos

Hi Mr "Box"

Can you tell me the binding path to your table's rows ? i.e. bindRows(?).

Thanks

-D

Former Member
0 Kudos

var oModel = new sap.ui.model.odata.ODataModel(serviceURL,true)

//code for adding filters, and then

oTable.bindRows("/MyEntitySet", null, null, filters);

note: renamed my entity set

former_member182862
Active Contributor
0 Kudos

Can you check the oData response. it may something like

var m = oTable.getModel().getProperty('/d/MyEntitySet');

or

var m = oTable.getModel().getProperty('/results/MyEntitySet');

Former Member
0 Kudos
var sPath = oEvent.getParameter("rowContext").getPath();

console.log(sPath);

output:

/EntitySet(param1='val1',param2='val2');

that's why its unable to push m[x]...! here x carries only index .. and it has to be something like sPath value. how to do that?

former_member182862
Active Contributor
0 Kudos

Hi

Maybe we want to try another way.

Example

(look for // change, places where I have made changes w.r.t. previous example)

-D

Former Member
0 Kudos

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..!

Answers (0)