LA.NET [EN]

Oct 23

We can reuse our knowledge of the previous post to create a master-detail scenario. The idea is simple: we configure our master DataView to show all the elements and then we add a second DataView control that will only show the details of the current selected item on the master DataView. I will spare you from long texts and I’ll jump right away into some code (I’m adapting the code from the previous post):

<body xmlns:sys="javascript:Sys"
      xmlns:dv="javascript:Sys.UI.DataView">
   <div id="master"
        class="sys-template"
        sys:attach="dv"
        dv:data="{{ arr }}"
        dv:selecteditemclass="selected"
        dv:initialselectedindex="0">
      <div sys:command="select">
          <span>{binding name}</span>-
          <span>{binding address}</span>
      </div>
   </div>
   <div id="detail"
        class="sys-template"
        sys:attach="dv"
        dv:data="{binding selectedData, source=$master}">
      <input type="text" sys:value="{binding name}" />
      <br />
      <input type="text" sys:value="{binding address}" />
   </div>
</body>



There are some observations I’d like to make about the previous snippet:



  • you’ll notice that I’ve removed the one-time/one-way bindings of the previous post. I’ve replaced them with live bindings to ensure proper propagation of changes made from the details DataView control;
  • still on the master, I’ve ended up adding two span elements because you can’t put two binding expressions within a single tag;
  • the details DataView control is configured so that it gets its data from the selectedData property of the master DataView control. The selectedData references the object used to fill the current selected item of the DataView control (ie, it references one of the objects from the arr array). Notice that any modifications performed over this object will also be replicated  on the master DataView control because we’ve used live bindings on it between each object of the arr array and each line generated through template instantiation;
  • since we’re applying live bindings to INPUT elements, we can get away with not setting the mode to twoWay (remember that you’ll get the default auto mode which is translated into twoWay for INPUT controls);


And that’s it: as you can see, no JS code and you get updates everywhere.



However, this might not be what you want in some scenarios. You might be interested in having a traditional form where you need to click an edit button for editing an item and then need to click on the confirm on cancel button before making the change persistence. This requires some code, but it’s not that complicated with preview 6. On the next post we’ll see work in this scenario and we’ll see how things have become really really easy! Stay tuned for more.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>