Announcement

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

    Adding new record to a list grid

    Hi,

    We have the following requirements :
    1. Need to add a new record to a list grid.
    2. Listgrid is not sortable.
    3. Need that record to be added just above the last record present in the listgrid and the last record is not fetched from the database initially. It is generated on the fly in the Servlet class.

    We have done the following steps for that:
    First I'll take the last record and pass that to removeData() and pass the same last record to the addData(), after adding the new Record.

    listGrid.removeData(recordLast);
    listGrid.addData(newrecord);
    listGrid.addData(recordLast);

    Since this last record is not there in the database, I can't delete it from the database. So I have a empty remove method in my servlet which just returns the dsResponse.
    I tried deleting the last record from the datasoruce, even that is not working.

    Please let me know if there is any other way in which I can fit in the new record just above the last record.

    Thanks,
    Keerthi.

    #2
    Hi Keerthi,

    Can you provide a little context on what you are trying to do from the end user's perspective - is this a server-generated summary row you are trying to add? The approach we would recommend is going to be very different depending on what you are trying to achieve, again, from the end user's perspective.

    Also, is this a dataset where you need to use paging?

    Comment


      #3
      Hi,
      I will give a Retail Outlet example, where I have the list of items and its attributes which I will have in a listgrid called
      listItems. We will have the Total also as the last row in this listgrid, which I calculate in the Java side, add to the resultset list at the bottom and send
      through the dsresponse.

      Item Price MRP Profit
      Item1 100 -- --
      Item2 200 -- --

      Total 300 -- --



      Now, the user wants to add one item into this list. We will give him a pop-up window and can select an item which has to be
      added to the listitems.
      So when he adds the new item 'Item3', he should be able to add the new item in between 'Item2' and 'Total' rows.

      For that I am using the following code,

      listitems.addData(newrecord);

      And I have an add() method in the servlet which will set the new record to the listitems.
      But the problem here is when I do this, it will be added to only after the 'Total' row.
      But instead, I want this new row to be added in between 'Item2' and 'Total' rows.

      I also thought of having a seperate listgrid, named listtotal for displaying only 'Total', so that I can add all the new items to the listitems
      itself.
      But the number of rows and columns in the listitems is dynamic, so the width and height may vary accordingly.
      So if I keep another listgrid, there may be so much gap between the listitems and listtotal, which will not look good from
      a user's perspective. Also, if there are many columns there will be horizontal scrollbars for both the listgrids, which will also not look good.
      That's why I decided to have the Total also in the same listgrid, so that there won't be any space between the items and the
      Total and the scrollbar issue also won't occur.

      Please let me know how I can solve this issue.

      Thanks,
      Keerthi.

      Comment


        #4
        You should either go with two ListGrids, or you should go with a single ListGrid in which you have provided the data as a simple Array rather than working with a databound ResultSet. By trying to manage your totals row as a "fake" row tacked onto the end of a paging ResultSet is going to be harder than either of these other two approaches.

        In the case of using a simple Array as the data, use the List APIs to manipulate the data directly - this will allow you to place your rows exactly where you want to, because you can just do eg list.set(index, record). You can still separately interact with a DataSource, using DataSource.fetchData() to get the data initially, and calling eg DataSource.addData() when you add new records that should be saved.

        In the case of using two parallel ListGrids, set the second grid's bodyOverflow to "hidden" to prevent a second scrollbar, and use overrides of scrolled() and fieldStateChanged() to facilitate keeping the two grids in sync.

        Comment


          #5
          Hi,

          I have added the new row using the list, as you mentioned.
          But the problem here is the newly added row is not getting added to the cache. So for the calculations I do on the rows of the listgrid, the newly added row is not taken into account.
          I take all the rows from the listgrid to the Java side and do some calculations on the rows and want to display them back in the listgrid. But the data which I get from the calculations is not reflecting in the newly added row alone.
          Is that because the newly added row is not there in the cache?
          If that is the case, please let me know how I can have the new row in the cache.

          Thanks,
          Vineeth.

          Comment


            #6
            Hi Vineeth,

            Sorry, that's not making much sense to us. Which of the two suggested approaches are you using? What is the "cache" that you are referring to - you seem to be talking about something separate from the ListGrid's data object, but SmartClient does not maintain any separate cache?

            Comment


              #7
              Originally posted by Isomorphic
              In the case of using two parallel ListGrids, set the second grid's bodyOverflow to "hidden" to prevent a second scrollbar, and use overrides of scrolled() and fieldStateChanged() to facilitate keeping the two grids in sync.
              is this approach feasible when the grid has a large number of columns and needs an horizontal scrollbar (and also a vertical scrollbar)?

              I don't understand if it's the VLayout containing the grids that must have the scrollbars or the grids themselves.

              Comment


                #8
                Hi claudio,

                Yes it's feasible with a large number of columns. The grid itself has the scrollbar in this case.

                Comment


                  #9
                  ok, but if I
                  Originally posted by Isomorphic
                  set the second grid's bodyOverflow to "hidden" to prevent a second scrollbar
                  then I obtain an horizontal scrollbar between the first grid and the "footer" grid. I don't feel it's appealing.
                  I'd like to have it under the footer grid. I'm thinking that the optimum may be to have the horizontal scrollbar under the footer grid, and a vertical scrollbar to scroll only the first grid.
                  Is it possible? Is it possible to set the vertical and horizontal overflow independently?
                  Last edited by claudiobosticco; 16 Dec 2008, 00:45.

                  Comment


                    #10
                    I'm almost succeeding in obtaining this listgrid with an horizontal scrollbar under the footer, a vertical scrollbar for the rows, and fixed header and footer.
                    I promise I'll share my (poor?) solution.

                    Comment

                    Working...
                    X