0

Insert New Record at the top of Grid / Listbox using Inline Editing

asked 2015-08-11 15:24:40 +0800

ifmis gravatar image ifmis
1 2

When we display a list of items on a screen that has more rows than what we can display on one page; the user advances to the next page and then wants to insert a new record, the new record is added in the beginning (first page of the list). As the user is on the other page, he will not be able to see this new inserted record.

My requirement is that when this scenario happens, after inserting a new record the application must navigate automatically to the first page and set the focus on the first newly created line.

In ViewModel, I am using:

 /**
 * On add new action command.
 * allRecordsInDb -- the list of all my objects
 */
@Command
@NotifyChange({ UIConstants.ALL_RECORD_IN_DB, UIConstants.DISPLAY_EDIT })
public void onAddNew() {

    Currency object = new Currency();
    object.setEditStatus(true);

    allRecordsInDB.add(0, object); // add the object on the beginning of the list.

}

May anyone have an idea how I can achieve this?

I tried to use a zscript function with this binding command but I didn't have chance to overcome this challenge because it seems not to be supported.

<zscript><![CDATA[
        void changePage(){
            int cp = grid.getPaginal().getActivePage();
            System.err.println(cp);

            grid.getPaginal().setActivePage(0);
            int cp2 = grid.getPaginal().getActivePage();
            System.err.println(cp2);
        }
    ]]></zscript>

Thank you.

Emma

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2015-08-14 14:58:32 +0800

cyiannoulis gravatar image cyiannoulis
1191 10

I think it is quite simple if you bind the activePage property to the view model. Changing the value of the currentPage will navigate automatically to the page you want:

<grid activePage="@bind(vm.currentPage)" />

/costas

link publish delete flag offensive edit

answered 2015-08-19 06:51:34 +0800

ifmis gravatar image ifmis
1 2

updated 2015-08-19 07:04:43 +0800

/**
 * On add new action command.
 * allRecordsInDb -- the list of all my objects
 */
@Command
@NotifyChange({ UIConstants.ALL_RECORD_IN_DB, UIConstants.DISPLAY_EDIT, "currentPage" })
public void onAddNew() {

    Currency object = new Currency();
    object.setEditStatus(true);

    allRecordsInDB.add(0, object); // add the object on the beginning of the list.
    setCurrentpage(0);             // navigate to the first page of the grid

}

The attribute activePage works effectively. And as seen above remember to add @NotifyChage("currentPage").

<grid activePage="@bind(vm.currentPage)" />

Many thanks to costas.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2015-08-11 15:24:40 +0800

Seen: 32 times

Last updated: Aug 19 '15

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More