Question

I have a listbox with listitems. choosen by user listitems become columns of the new created table, so I have to bind property "text" of the listitem with property "text" of the column; the same counts for property "visibility" and "sortOrder". I couldn't find property "visibility" and "order" for listitem to bind them with the same ones via JSONmodel. Anyone wh o has more experience on it? second Q: here is my trial of binding, which doesn't work, please check the logic. Ex. of listbox + listItem:

var listboxChooseColumns = new sap.ui.commons.ListBox("chooseColumns", {

                                                       allowMultiSelect: true,
                                                       items:
                                                                      [
                                                     new sap.ui.core.ListItem({
                                                                                          text: "Export number"     })]})

here is the way I tried to bind prop"text" of listitem with JSONmodel:

sap.ui.getCore().getModel().setProperty("{/visibleColumns/" + listItem.text +"}",  true);

here is an example of table column:

   table.addColumn(new sap.ui.table.Column({
    label : new sap.ui.commons.Label( {
        text : "{/visibleColumns/columnName}"
             })}));

here is JSONmodel:

 sap.ui.getCore().setModel(new sap.ui.model.json.JSONModel({
  columns: [
                { columnName: "Ëxport Number",
                visible: true,
                columnorder: 1
            },
   {
                columnName: "Functional Location",
                visible: true,
                columnorder: 1
              }]  
 }));

But still somewhere I went wrong. Any ideas ?

Was it helpful?

Solution

I think you can determine visibility and order as well; the visible columns would be the selected items in your ListBox, and the order would be the order in which they appear in your ListBox

So when you alter the contents in your listbox (adding/removing items, changing the order in your listbox) this would also alter your model.

If you now create a template element for the table's columns, you can now simply use the 'bindColumns' method:

var oColumnsTemplate = new sap.ui.table.Column({
    label : new sap.ui.commons.Label().bindProperty("text", "columnName")
});
table.bindColumns("/columns", oColumnTemplate);

and the selected ListItems will now render a table with columns in the correct order.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top