Announcement

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

    ListGrid.getOriginalData()

    Build:
    Browser: Any
    Problem: Currently we pass dynamic value maps as part of the first record that we send over to the listgrid. When we call getEditorValueMap(), we do listGrid.getRecord(0).valueMapName . Unfortunately, this does not work when the data gets sorted in the browser. listGrid.getRecord(0) returns the first record on the sorted list.

    So I tried to instead use listGrid.getOriginalData().get(0) - same problem. The documentation does say that it would give me the original UNGROUPED data - but I guess this means when there's a groupBy on the listGrid? Is there any way to get the original data BEFORE the configured sorting?

    Steps to reproduce:

    In the same, click on current record 0 button - it will return China.
    Now click on original record - it will also return China.
    The first record in countryData is United States - I would like this information.


    Code:
    countryData = [
    
    {
        continent:"North America",
        countryName:"United States",
        countryCode:"US",
        area:9631420,
        population:298444215,
        gdp:12360.0,
        independence:new Date(1776,6,4),
        government:"federal republic",
        government_desc:2,
        capital:"Washington, DC",
        member_g8:true,
        article:"http://en.wikipedia.org/wiki/United_states"
    },
    {
        continent:"Asia",
        countryName:"China",
        countryCode:"CH",
        area:9596960,
        population:1313973713,
        gdp:8859.0,
        government:"Communist state",
        government_desc:0,
        capital:"Beijing",
        member_g8:false,
        article:"http://en.wikipedia.org/wiki/China"
    },
    {
        continent:"Asia",
        countryName:"Japan",
        countryCode:"JA",
        area:377835,
        population:127463611,
        gdp:4018.0,
        government:"constitutional monarchy with parliamentary government",
        government_desc:1,
        capital:"Tokyo",
        member_g8:true,
        article:"http://en.wikipedia.org/wiki/Japan"
    },
    {
        continent:"Asia",
        countryName:"India",
        countryCode:"IN",
        area:3287590,
        population:1095351995,
        gdp:3611.0,
        independence:new Date(1947,7,15),
        government:"federal republic",
        government_desc:2,
        capital:"New Delhi",
        member_g8:false,
        article:"http://en.wikipedia.org/wiki/India"
    },
    {
        continent:"Europe",
        countryName:"Germany",
        countryCode:"GM",
        area:357021,
        population:82422299,
        gdp:2504.0,
        independence:new Date(1871,0,18),
        government:"federal republic",
        government_desc:2,
        capital:"Berlin",
        member_g8:true,
        article:"http://en.wikipedia.org/wiki/Germany"
    },
    {
        continent:"Europe",
        countryName:"United Kingdom",
        countryCode:"UK",
        area:244820,
        population:60609153,
        gdp:1830.0,
        independence:new Date(1801,0,1), 
        government:"constitutional monarchy",
        government_desc:1,
        capital:"London",
        member_g8:true,
        article:"http://en.wikipedia.org/wiki/United_kingdom"
    },
    {
        continent:"Europe",
        countryName:"France",
        countryCode:"FR",
        area:547030,
        population:60876136,
        gdp:1816.0,
        government:"republic",
        government_desc:5,
        capital:"Paris",
        member_g8:true,
        article:"http://en.wikipedia.org/wiki/France"
    },
    {
        continent:"Europe",
        countryName:"Italy",
        countryCode:"IT",
        area:301230,
        population:58133509,
        gdp:1698.0,
        independence:new Date(1861,2,17),
        government:"republic",
        government_desc:5,
        capital:"Rome",
        member_g8:true,
        article:"http://en.wikipedia.org/wiki/Italy"
    },
    {
        continent:"Asia",
        countryName:"Russia",
        countryCode:"RS",
        area:17075200,
        population:142893540,
        gdp:1589.0,
        independence:new Date(1991,7,24),
        government:"federation",
        government_desc:3,
        capital:"Moscow",
        member_g8:true,
        article:"http://en.wikipedia.org/wiki/Russia"
    },
    {
        continent:"South America",
        countryName:"Brazil",
        countryCode:"BR",
        area:8511965,
        population:188078227,
        gdp:1556.0,
        independence:new Date(1822,8,7),
        government:"federative republic",
        government_desc:3,
        capital:"Brasilia",
        member_g8:false,
        article:"http://en.wikipedia.org/wiki/Brazil"
    },
    {
        continent:"North America",
        countryName:"Canada",
        countryCode:"CA",
        area:9984670,
        population:33098932,
        gdp:1114.0,
        independence:new Date(1867,6,1),
        government:"constitutional monarchy with parliamentary democracy and federation",
        government_desc:1,
        capital:"Ottawa",
        member_g8:true,
        article:"http://en.wikipedia.org/wiki/Canada"
    },
    {
        continent:"North America",
        countryName:"Mexico",
        countryCode:"MX",
        area:1972550,
        population:107449525,
        gdp:1067.0,
        independence:new Date(1810,8,16),
        government:"federal republic",
        government_desc:2,
        capital:"Mexico (Distrito Federal)",
        member_g8:false,
        article:"http://en.wikipedia.org/wiki/Mexico"
    },
    {
        continent:"Europe",
        countryName:"Spain",
        countryCode:"SP",
        area:504782,
        population:40397842,
        gdp:1029.0,
        independence:new Date(1492,0,1),
        government:"parliamentary monarchy",
        government_desc:4,
        capital:"Madrid",
        member_g8:false,
        article:"http://en.wikipedia.org/wiki/Spain"
    },
    {
        continent:"Asia",
        countryName:"South Korea",
        countryCode:"KS",
        area:98480,
        population:48846823,
        gdp:965.3,
        independence:new Date(1945,7,15),
        government:"republic",
        government_desc:5,
        capital:"Seoul",
        member_g8:false,
        article:"http://en.wikipedia.org/wiki/South_korea"
    },
    {
        continent:"Asia",
        countryName:"Indonesia",
        countryCode:"ID",
        area:1919440,
        population:245452739,
        gdp:865.6,
        independence:new Date(1945,7,17),
        government:"republic",
        government_desc:5,
        capital:"Jakarta",
        member_g8:false,
        article:"http://en.wikipedia.org/wiki/Indonesia"
    }
    
    ]
    
    
    
    isc.ListGrid.create({
        ID: "countryList",
        width:500, height:224, alternateRecordStyles:true,
        data: countryData,
        fields:[
            {name:"countryCode", title:"Flag", width:50, type:"image", imageURLPrefix:"flags/16/", imageURLSuffix:".png"},
            {name:"countryName", title:"Country"},
            {name:"population", title:"Population", formatCellValue:"isc.Format.toUSString(value)"},
            {name:"area", title:"Area (km²)", formatCellValue:"isc.Format.toUSString(value)"}
        ],
        // initial sort on Population, high-to-low
        sortFieldNum: 2,
        sortDirection: "descending"
    })
    
    isc.Button.create({
    ID: "test",title:"current record 0",
    top: 500,
    click: function(){
         isc.warn(countryList.getRecord(0).countryName);
     
    }
    
    })
    
    
    isc.Button.create({
    ID: "te2st",
    top: 500,left:200,title: "original record",
    click: function(){
         isc.warn(countryList.getOriginalData().get(0).countryName);
     
    }
    
    })

    #2
    No, we don't store off a parallel array of the unsorted data anywhere.

    Comment


      #3
      Well, do you have any suggestions on how to get around this? We don't really want to send the valuemaps for every single record when they are exactly the same - our value maps can be quite lengthy

      Comment


        #4
        We've mentioned a few times that your strategy doesn't match what's recommended in the docs, it's a kind of "worst of both worlds" that introduces the complexity of a valueMap embedded in the data, while not handling large valueMaps efficiently. See listGridField.optionDataSource for the recommended approach.

        Comment


          #5
          OK. Trying this optionDataSource approach - how do I catch the request before it is sent to the server so that I can add my own criteria? I want to add the record key to pass to the server. Also, how do I force it to fetch for every record that goes into edit mode? It looks like the optionDataSource fetch is only executed on the first edit. getEditorValueMap is called every time but do you recommended doing the custom fetch there?

          Comment


            #6
            Override SelectItem.getPickListFilterCriteria() - see the DataBound Dependent Selects examples for sample code.

            If the criteria are the same, you will not see a new fetch, so changing the criteria per-record should solve that issue too.

            No, do not attempt a fetch from getEditorValueMap.

            Comment


              #7
              I see how this can work - but how do I get access to the current record in edit mode? I would need to find the listgrid via global ID and get the currently editing row?

              Comment


                #8
                See the DataBound Dependent Selects example. It accesses the record values in order to get the value for another field.

                Comment


                  #9
                  whoops thanks - was looking at the wrong example.

                  Comment


                    #10
                    Here's what I got so far. I have a sample of a listgrid with one dropdown. I have the optionDataSource bound to "optionDs" BUT it only works if I have the data like testEnum2 - I want to work with testEnum where I have the key/value pair- otherwise I'm not sure how to get the actual key instead of the description (value).


                    Code:
                    isc.ListGrid.create({
                        ID: "countryList",canEdit:true,
                        width:500, height:224, alternateRecordStyles:true, 
                        dataSource: countryDS,
                        fields: [{name: "countryName", optionDataSource: "optionDs"}],
                        autoFetchData: true
                    })
                    
                    //listgrid ds
                    
                    isc.DataSource.create({
                        ID: "countryDS",
                        fields:[
                            {name:"countryName", title:"Country"},
                            {name:"countryCode", title:"Code"},
                            {name:"independence", title:"Independence", type:"date"},
                            {name:"population", title:"Population", type:"integer"},
                            {name:"gdp", title:"GDP ($B)", type:"float"}
                        ],
                        clientOnly: true,
                        testData: countryData
                    })
                    
                    //optionDataSource
                    
                    var   testEnum = [
                                {
                                    countryName:{
                                        "1":"test1", 
                                        "2":"test2", 
                                        "3":"test3"
                                    }
                                }
                            ];
                    
                    var   testEnum2 = [
                                {countryName:"test1"},
                                {countryName: "test2"},
                                {countryName:"test3"}
                                   ];
                    			   
                    
                    isc.DataSource.create({
                    ID:"optionDs",
                    fields:[{name:"testEnum"}],
                    clientOnly:true,
                    testData:testEnum2
                    });
                    Last edited by acarur01; 1 Aug 2012, 11:21.

                    Comment


                      #11
                      The data for the DataSource should be standard Records, not some kind of nested structure. So each should be a JavaScript Object with an id field and a display field. You tell the optionDataSource which fields to use via selectItem.valueField and displayField.

                      Comment

                      Working...
                      X