Skip to Content
0

Populate grid table SAPUI5 dynamically

Nov 02, 2017 at 02:19 AM

112

avatar image

Hi Expert,

I would like to implement development in SAPUI5 whereby user able to enter number of column and grid to be generated. The grid should triggered an event to pop up message whereby which column and row is clicked.

http://jsfiddle.net/6qkdP/2/

May I know which control available in SAPUI5 able to achieve this objective.

I've tried 'sap.ui.table' but was getting error "method "addRow" cannot be used programmatically!" while generating the grid.

How should I design XML view as the view will be generated dynamically?

Any help would be much appreciated.

Thanks.

Regards,

-Ben-

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Yen Shen, Ben Lim Nov 06, 2017 at 11:35 AM
1

Hi All,

I managed to populate the grid dynamically.

Below are my xml view and controller.

Thanks to Arjun Biswas and Joseph BERTHE for your guide.


1.png (30.8 kB)
2.png (38.1 kB)
Share
10 |10000 characters needed characters left characters exceeded
Arjun Biswas Nov 02, 2017 at 03:55 AM
1

May be you can extend the sap.ui.table.Table control, to achieve your objective in SAPUI5. You can use the "attachRowSelectionChange" method to get which row is selected in the table.

Show 4 Share
10 |10000 characters needed characters left characters exceeded

Hi Arjun Biswas,

Appreciate your comment. Is there any control in XML view to be created? Is it the table creation is done via in controller? I've checked on the sap.ui.table.Table documentation, to add row, we need to have data binding. But for my case, the data to be populated in each cell will by dynamic. How can I bind these dynamic value to each cell?

0

Thankyou Yen Shen, Ben Lim,

Yes, you need to create an sap.ui.table.Table in your XML view, after that, you have to bind the data (your dat) to the table, as you said your data will be dynamic. To bind dynamic value to each cell, you can use the bindRows method, wherein you can bind the whole row of the table.

Also you can use the cellClick method to handle the click event of any cell.

In the controller, just set the model to your table and you are good to go, for your application.

Hope this helps,

Regards.

0

Hi Arjun Biswas,

I'm able to bind the row dynamically as for now. But how could I declare the columns in xml view? In my current xml view, I've add column name {name}. How could I achieve to make it populate dynamically?

1.png (37.0 kB)
0

Hi Yen Shen, Ben Lim,

You can give an id to your column, and from your controller's init function, you can set the table header using the foll code :

<yourColumID>.setHeader(new sap.m.Label({text:modelTableHeader.oData.COLUMN1}));

Hope this helps,

Regards.

0
Joseph BERTHE Nov 03, 2017 at 12:49 PM
1

Hello,

You can bind your table to a JSon model. please look at this example : https://stackoverflow.com/questions/21731176/dynamic-binding-of-table-column-and-rows

Regards,

Share
10 |10000 characters needed characters left characters exceeded