Anand
Anand

Reputation: 21320

Inline editing in GWT cell table

I have a cell table in one of my GWT screen. Now requirement is that there will be some button on the screen clicking on which one editable row will be inserted into the cell table. if I am not wrong this is called inline editing.

Can somebody please help me with that? I have just started working in GWT.

Upvotes: 3

Views: 4255

Answers (1)

cardamo
cardamo

Reputation: 853

Here is very simple example of adding new editable row to the celltable. I hope I understand what you meant :)

public class Test
implements EntryPoint
{
    public void onModuleLoad()
    {
        //create and attach table
        final CellTable<A> table = new CellTable<A>();
        RootPanel.get().add(table);

        //add editable cell
        table.addColumn(new Column<A, String>(new TextInputCell())
        {

            @Override
            public String getValue(
                A object)
            {
                return object.getA() == null ? "" : object.getA();
            }
        });

        //put some data
        ListDataProvider<A> dataProvider = new ListDataProvider<A>(
            Arrays.asList(new A("AAA"), new A("BBB"), new A("CCC")));
        dataProvider.addDataDisplay(table);

        //add button with click handler
        RootPanel.get().add(new Button("add new", new ClickHandler()
        {

            @Override
            public void onClick(
                ClickEvent event)
            {
                //add new object to visible items
                List<A> data = new ArrayList<A>(table.getVisibleItems());
                A newOne = new A();
                data.add(newOne);
                table.setRowData(data);
            }
        }));
    }

    class A
    {
        String a;

        public A(
            String a)
        {
            super();

            this.a = a;
        }

        public A()
        {
            super();
        }

        public String getA()
        {
            return a;
        }

        public void setA(
            String a)
        {
            this.a = a;
        }
    }

Upvotes: 1

Related Questions