Announcement

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

    Adding a row in between two rows in list grid

    Hi

    I have created a list grid containing, say 2 rows. I have a button below the grid. on click of the button i should add a row in between the rows and the contents of the first row should be copied to the newly added row.
    Is it possible to achieve this in smart client. If yes how?

    Thanks in advance
    Strive

    #2
    Yes, it is. The simplest way to do is to have the grid be sorted and ensure the added record sorts between the other two records. However we might suggest other approaches if you explained your use case further.

    Comment


      #3
      Thanks for the reply...

      Assume my table is:
      Code:
              column1  column2   column3
      Row1    value1     value2     value3
      Row2    value4     value5     value6
      On click of a button, say copy row
      My table should look like:
      Code:
              column1  column2   column3
      Row1    value1     value2     value3
      RowNew  value1     value2     value3
      Row2    value4     value5     value6
      New row should be inserted in the place of Row2 and Row2 should move down.

      Comment


        #4
        Hi Strive - yes, that's what you said before - by "use case" we meant describing what the data means to the actual user of the application, and whether it is persisted, etc.

        Comment


          #5
          I get the data from the database and populate it in the table.

          Yes the data is persisted.

          Comment


            #6
            Again when user clicks on the save button on the screen, the data is stored in the database and three rows should be displayed on the screen.

            Comment


              #7
              Hi Strive,

              You still haven't mentioned what the data actually means to the user of the application. So far, our recommendation remains the same:

              The simplest way to do is to have the grid be sorted and ensure the added record sorts between the other two records.

              Comment


                #8
                Hi Isomorphic,

                I did not understand what you mean "What the data actually means to the user of the application" eventhough it is a straight forward question. I am sorry. I am trying my level best to explain you with an example.

                Say i am maintaining a drug store. i maintain the database to know the number of customers who registers in my drug store. It is a simple database table with three columns; country code, State code and customer id.
                On the screen i display the table in the following order of columns.
                1. Country code 2. State code 3. customer id
                Say i have logged into the application and the table is displaying two rows of data.
                1st row: country code -- USA, State code -- IL, customer id -- 1001
                2nd row: country code -- UK, State code -- TB, customer id -- 1002

                Now a new customer has entered into the store. He/she belongs to USA,IL.
                Now what i feel is, instead of entering all the values let me press a button where a new row is added copying country code as USA and state code as IL. I will just enter the customer id.


                Note: The solution you gave"The simplest way to do is to have the grid be sorted and ensure the added record sorts between the other two records" is good enough to solve my problem as my country code column is sortable.
                Can you please let me know "is there any inbuilt feature to add rows like this dynamically" or should i write my custom code to achieve this functionality.


                Thanks a lot Isomorphic for your replies.
                Strive

                Comment


                  #9
                  Hi Strive,

                  Your drugstore example is what I was looking for. If, alternatively, you wanted to insert a row at the second to last position because you were using the last row to show totals, that would have meant a different approach was better.

                  Yes, SmartClient has built-in functions for adding data. Start with the QuickStart Guide, Chapter 6, DataBinding. You will most likely end up providing a sort direction via grid.sort() and adding new rows via grid.addData. Sorting a new row into place with respect to the current sort behavior is an automatic behavior.

                  Comment


                    #10
                    I came across this issue today and your comment

                    "using the last row to show totals, that would have meant a different approach was better"

                    makes me wonder what that other approach might be. Let's say my requirement is to produce intermediary totals in a ListGrid, like

                    Code:
                    prod,carrier,cost
                    1234,UPS,31.00
                    2234,UPS,6.00
                    ----,----,37.00
                    1556,USPS,6.00
                    4567,USPS,4.00
                    ----,----,10.00
                    I know that I can create this on the server, using a hidden field to indicate the row type is TOTALS and apply a bold styling, for example. Then I could separate the totalled groups with a ListGrid row set to SingleField. But is there a better way to do this?

                    Pete

                    Comment


                      #11
                      Hi Pete,

                      If you have a single totals row, it be can be easier to represent it as a single row ListGrid, immediately below the main ListGrid, with the whole ensemble made to look like a single grid by just placing them in a VLayout. The advantage is that, since all rows in the main ListGrid remain ordinary ListGrid data, you avoid having to create a number of special cases for the total rows, such as using different formatting and avoid direct editing of totals. You can also scroll the main ListGrid keeping the totals row in view.

                      If you have multiple inline totals, the approach you're already using is probably the least complex.

                      Comment

                      Working...
                      X