Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Appropriate Use of DetailViewer?

    Hi there,

    This is my first post here, though I've been lurking for a couple of months now. I've started using SmartClient v8 (client-side JS only, no GWT at this time) in my first project and it's been a great toolkit so far.

    The short version of my question is this: when is appropriate to use the DetailViewer object?

    The longer version: I'm developing a screen that has a master/detail layout. Each master record is displayed in a grid and has a few fields. The details are displayed in multiple tabs, with the content of each tab provided by a separate datasource. This is being done because the master record is just an account number and customer name, while the details illustrate various other data concepts, depending on the type of client, the security level of the user, etc... The usual stuff. So far, so good.

    The tabs are meant to display read-only data, so as to minimize transaction overhead. If the user wants to edit the data on the tab, they click on an edit button and the tab's contents are replaced with a form. Still, so far, so good.

    On one of the detail tabs, I'm using a DetailViewer. Looking through the various examples and documentation, this approach was the closest that I could find to what I wanted, with the possible exception of using a table and a bunch of labels. The data feeding the DetailViewer is JSON and has a complex structure, but this also hasn't been an issue, thanks to the helpful information found elsewhere in the forum.

    Here's where things start to give me a problem. One of the fields is an array of values - in this case, first and last names. I'm currently trying to figure out how to render the list. I'm also trying to figure out how to concatenate values into a single field (e.g. LastName + "," + FirstName). Ultimately, I would like to have each name in the list as a clickable field. I can get the DetailViewer to recognize the list itself, but since each item in the list is an object (lastname and firstname), the output is "[Object object]" for each item. My best guess so far was to use a DetailFormatter but I'm not sure as to its correct use for lists and concatenation. And while I'm groveling for free help, I ultimately need to filter the items in the list based on each items value. Again, I'm guessing DetailFormatter is the correct choice but I'm not sure how to use it correctly.

    My question is basically is this possible to do? Where can I find the relevant information in the user documentation? Most importantly, is this even the right approach or is there a better way?

    Any help is appreciated.

    Thanks in advance,

    Sol
    Last edited by solstice; 21 Mar 2011, 10:48.

    #2
    Proving that you'll get working code if you just punch in random characters long enough, I got it to work through trial, error, and borrowing code from the ListGrid

    Code:
    isc.DetailViewer.create({
       ID: 'dvwrDepartmentOverview',
       dataSource: 'dsDepartmentOverview', 
       width: '100%',
       margin: '25',
       fields:[
          {title: 'Department Name', 'deptname'},
          {title:'Employees', name:'employees', 
             formatCellValue: function formatCellValue(value, record, field, viewer) {
                var sb = new StringBuffer();
                var count = 0;
                for(var i = 0; i < value.length; i++) {
                   if(value[i].employeeType != 2) {  // filtering on an arbitrary value
                      if(count > 0) sb.append('<br/>');  // adding line breaks for each item if needed
                      sb.append( value[i].lastName).append(', ').append(value[i].firstName);
                      count++;
                   }                     
                }
                return sb.toString();
             }
          }
       }
    }

    The example above is filtering on employee type - we're only interested in those employees of type "2". We're also adding in line breaks which is arbitrary HTML. It's simple enough to add links and so on from here. The StringBuffer object referenced is analogous to Java's StringBuilder/StringBuffer objects.

    So, it's working, which brings me back to my primary question: Is this the best approach?

    Thanks!
    Last edited by solstice; 22 Mar 2011, 07:16.

    Comment


      #3
      So, any advice on where to find information on best practices for developing UIs with SmartClient?

      Comment

      Working...
      X