0

In the items property of Table I set my path:

 items="{path: 'model>/elements/idStabMagTable/elements/'}">

Now I want map two different model (model with data and enable that manage the type of row)

            <items>
                <ColumnListItem type="{enable>row_enable}"> //"Navigation" or none
                    <cells>
                        <Text text="{model>society/description}"/>

                      ...

                    </cells>
                </ColumnListItem>
            </items>

This is my model model:

"idTable": {
      "elements": [
        {
          "language": {
            "code": "01",
            "description": "ITALIANO"
          },
          "scheda": "rome"
        },
        {
          "language": {
            "code": "04",
            "description": "TEDESCO"
          },
          "scheda": "berlino"
        }
      ]
    }

and this is my model enable

"idTable": {
      "elements": [
        {
          "language": true,
          "scheda": true,
          "_row": true
        },
        {
          "language": false,
          "scheda": false,
          "_row": false
        }
      ]
    }

I save the two models into two different file and I manage it into two different JSONModel. Now I want in each row set the values by the first model and the enable information by the 2nd model

But in items path I can map only one path! Can I map two model? (model and enable)

padibro
  • 1,324
  • 10
  • 56
  • 95
  • 1
    Not sure what you're looking for... in `items`, you can only loop through one array, but you could use as many models in your table as you would. Looking at your code, I don't see anything wrong -- except that there is of course no relationship between model `enable` and model `model`, is that what you're after? Can you elaborate a bit more on what you're after? – Qualiture Jan 13 '15 at 12:08
  • So, if I understand correctly, you want each entry in `model` correspond with an entry in `enable`? I think you need to do the linking yourself, maybe with a formatter function for the `type` property you want to set... but isn't it simpler to just combine both models into one? – Qualiture Jan 15 '15 at 12:00
  • Any solution? this is a bad problem form me.. now I have also another model (state model that have valueState and valueStateText info for each field) and I not want include all in one model! – padibro Mar 09 '15 at 10:54
  • 1
    Unless you can identify which entry in your `enable` model corresponds with the entry in your `model` model, there is no safe way to link these (due to sorting/grouping). But if this isn't an issue for you, then use a formatter function (get the index from your `model` item, and return the value from the corresponding `enabled` model item index. But again, you better have them linked by a unique identifier – Qualiture Mar 09 '15 at 11:04
  • Yes! but how can I retrieve the index to pass to Formatter? can I extract the index of the item? For example the full path for a row is `model>/elements/idStabMagTable/elements/3/society/description` . If I can to retrieve the index `3` I use it to write the full path from the other model: `enable>/elements/idStabMagTable/elements/3/society` – padibro Mar 09 '15 at 11:05
  • 1
    Of course you can get the index and use that, but like I said, only if you're **absolutely sure** there's no filtering, sorting or grouping in both arrays or table – Qualiture Mar 09 '15 at 11:07
  • Are you sure that is important that there's no filtering, sorting or grouping? If without sorting, for example, the item is shown in 2nd position and if sorting is on it switch in 1st position the path that I retrieve is always `..../2/...` (the position of item in the array). or not? – padibro Mar 09 '15 at 11:10
  • Eh, yes of course. Index numbers will change inevitably (if your original table contains 20 rows and after filtering and sorting you will have only 10, then how would you know that former-row 20, now row 10, should link to row 20 of your enabled model? – Qualiture Mar 09 '15 at 11:13
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/72565/discussion-between-bradipo-and-qualiture). – padibro Mar 09 '15 at 11:18
  • In ColumnListItem I want retrieve the index of current item to pass to Formatter. How can I retrieve it? something like this? ?? – padibro Mar 09 '15 at 13:13
  • See http://scn.sap.com/message/15801405#15801405 on how to *properly* retrieve the index from the current item – Qualiture Mar 09 '15 at 15:05

1 Answers1

0

I have found my solution! It works fine and allow me to maintain differents models.

If in a Table (or List) I have this path for my elements:

items="{path: 'model>/elements/idStabMagTable/elements/'}">

if I want bind a property in the model model in ColumnListItem I write

<Text text="{model>society/description}"/>

If I have a 2nd model enable with the SAME STRUCTURE of model model I can map the same property but in the enable model in this mode:

<Text text="{parts:[{path:'model>society'}], formatter:'ui5bp.Formatter.elementEnable'}"/>

This is my formatter function:

 elementEnable: function (oEl) {
        var sPath = this.getBindingInfo("text").binding.oContext.sPath;
        var sProperty = this.getBindingInfo("text").parts[0].path;
        sPath=sPath+"/"+sProperty;
        var oEnableModel= ui5bp.products.getModel("enable"); //same path, different model
        var oValueEnable=oEnableModel.getProperty(sPath);
       return oValueEnable;
    }
padibro
  • 1,324
  • 10
  • 56
  • 95
  • 1
    I truly hope this works for you, but as I have stated before, [you cannot rely on a javascript array order](http://stackoverflow.com/questions/5773950/how-to-keep-an-javascript-object-array-ordered-while-also-maintaining-key-lookup). If I would do a code review, I would certainly reject this pattern – Qualiture Mar 10 '15 at 10:08