On buttonClick refresh the table with the new rows added - vaadin

I have created a table and a button. On click of that button i need to add the row.
For that i have used buttonClick method in which i am adding a row in the Table.
The problem is that the row in added to the table (I can see in the logs),
but the screen becomes blank with just the button displayed.
If I exit and navigate again to the screen, then i can see the new row added.
How can i see the new row added immeditalety once added.

Some code would probably help to further see what might be wrong, but I would also recommend you to call the following code line directly after you have added a table row.
yourTable.setContainerDataSource(yourTable.getContainerDataSource());
This will update the datasource for your table and force a repaint. If you provide some code maybe more help can be provided

Using IndexedContainer to add new row in table during button click..
Example
Create IndexedContainer
-----------------------
private IndexedContainer getTblTerminals(IndexedContainer container)
{
container.removeAllItems();
container.addContainerProperty("Terminal_Id", String.class, defaultValue);
g_TermialPojo=ws.readAll();
for(Terminal pojo:g_TermialPojo)
{
Object itemId=container.addItem();
strTid=String.valueOf(pojo.getTid());
container.getContainerProperty(itemId,"Terminal_Id").setValue(strTid.toString());
}
return container;
}
//To add indexedcontainer in your table
-------------------------------------------
Example
table.setContainerDataSource(getTblTerminals((IndexedContainer)table.getContainerDataSource()));
table.setImmediate(true);

Related

Show newly added record as dirty i.e. red color on top

I am adding new record in grid like below
var newRow = Ext.create(gridModel);
rowEditPlugin.cancelEdit();
gridStore.insert(0, newRow);
reportGrid.getView().refresh();
reportGrid.getView().getSelectionModel().select(0);
//rowEditPlugin.startEdit(0);
rowEditPlugin.startEditByPosition({
row: newRow,
column: 0
});
I want this newly added record to be shown as dirty, user should know that this row is added newly i.e. red marks on top of each column.
You can supply a method to the viewConfig of your grid, called getRowClass. This method will allow you to customise the CSS class for the row.
You can tell if your record is newly inserted or not using the Model#phantom property
And, finally, you can modify the CSS for your application using SASS/Fashion to change the appearance of your newly added rows.

How to reload parent view in Vaadin without table reseting sort order

I'm using PagedFilterTable in Vaadin to manage pagination. When loading default page, I have set something like this - and I include sorting by some field:
if(this.sortField != null){
table.setSortContainerPropertyId(this.sortField);
table.setColumnWidth(this.sortField, 80);
table.setSortAscending(true);
table.sort();
}
So that happens when the page is loaded and that is fine. After I submit new entry (entries are being added through new, popup window), table gets new row, but the table loses it's sort order in view after popup closes, so sorting is no longer keeped. Problem is I do not know how to get to that table element from that popup window and set sorting again. Why table is being updated and I see it, and sort doesen't? Problem is bigger because I have both windows in separate files and seems to me I can't grab table element easily without modifiying the logic because I am in another window.
How to reload table so that the sort stays same?
I managed to do this after submit:
getUI().getPage().reload();
With that it works, but I am not satisfied. After that line of code, everything reloads again (meaning all queries execute again). Result is good but I don't want after submit whole reloading of page happens (also because none of my other buttons do reload). So I would like only to reload table in parent window.
How can I grab table object from outside window and for example set it's change to immediate and correct change?
Something like this I suppose needs to be written:
getParent().getUI().setImmediate(true);
?
Or better question, how to manage to table sort remains the same after inserting new entry through new window?
I managed to solve it. On the parent window in the windowCloseListener I just added:
myTable.refreshTable(data);
myTable.sortTable(); // my custom method that was Invoked on the page load too

Populating UISearchBar with String from PrepareForSegue with CoreData/NSFetchedResultsController

I have a simple application which is a table view (TV1) that gets populated by the user tapping the plus button in the navigation bar. The user gets taken to an Add Entry screen where tapping on the "name" text field brings up another Table View (TV2) for the user to add existing entries, search for existing entries or add a new entry. This works really well and delegates ensures that what I select in the new Table view (TV2) populates the Name Text Field.
What I want to achieve is the other way around also; if a user has the name text field already populated and clicks on it to bring up the TV2, I want the search bar to already be populated with the string that was passed through while ensuring the searching still works.
For example, if I have the nameTextField with John, when I click on the nameTextField and get taken to the TV2, I want the searchBar.text to say John, but also for the searching to now only show entries with John in the name, just like it would be if I start typing the name John.
I am using Core Data and NSFetchedResultsController.
In the prepaeForSegue of the Add Entry, I am doing this:
if ([self.nameTextField.text length] > 0)
{
[envylopeNameTextFieldTableViewController setSelectedName:self.nameTextField.text];
}
In the TV2, the setSelectedName method is:
- (void)setSelectedName:(NSString *)selectedName
{
_selectedName = selectedName;
self.nameAddSearchBar.text = selectedName;
[self searchBar:self.nameAddSearchBar textDidChange:selectedName];
}
The last line in there is a trial by me because that method is what gets called when I start searching, so I thought I could call that. I tried it without it and with self.nameAddSearchBar.text = self.selectedName and _selectedName and nothing; the searchBar does not get populated.
With a breakpoint, I can see that selectedName = John and _selectedName = John, but self.nameAddSearchBar.text = nil.
I can imagine I'm one or two lines of code away, but I'm just not sure how to proceed.
Any assistance would be really great.
Thanks,
Try moving
self.nameAddSearchBar.text = selectedName
from the setter (-setSelectedName) into viewDidLoad in TV2. The issue here is that you're trying to assign nameAddSearchBar (a view) before it has loaded.
Since the search bar is part of the "view", it is not be available until "viewDidLoad". You can set the selectedName property with the right value and then update the view (search bar.txt) with that value once the view is loaded (in viewDidLoad).

BlackBerry 6: how to scroll to a new item in KeywordFilterList?

the SearchFieldDemo works well for me, but has one problem: when you add a new country to the KeywordFilterList through the menu and that new item is on the bottom of the sorted list, then the user doesn't see anything and is unsure if the new item has been added or not.
A solution would be to make the KeywordFilterList scroll to the new item, but I can't figure out, how to do that. I've tried:
void addElementToList(Country country)
{
_countryList.addElement(country);
_keywordFilterField.updateList();
int index = _countryList.getIndex(country);
System.err.println("XXX index: " + index);
_keywordFilterField.setSelectedIndex(index);
}
But this does not have any effect: the printed index is correct and the KeywordFilterList scrolls, but not to a correct spot.
Any ideas please?
Alex
In the sample app you might have noticed the _keywordFilterField.setKeyword(""); line as the first thing they do before adding a new item to the list. This is to guarantee the new item will be visible in the list. Otherwise with some filter applied the list may not display the new item.
So in your code it looks like you don't handle this point. As a result the index you get with int index = _countryList.getIndex(country); may not be the same as it is in the visible filtered by some current keyword list. BTW, to find the index in the visible list you could use the ReadableList which can be got with _keywordFilterField.getResultList().
So the workflow could be as follows:
reset keyword by _keywordFilterField.setKeyword(""); - now there is no filtering applied so the visible list should include a new item.
add a new item to the underlying collection - _countryList.addElement(country);
call _keywordFilterField.updateList(); to refresh the ListField.
to be on the safe side find an index to scroll to by using the collection got by calling the _keywordFilterField.getResultList()
select the new item with _keywordFilterField.setSelectedIndex(index);

not able to select added rows in a table JQuery

i'm adding rows to table dynamically, but the problem is i'm not able to select or activate when i click on the added rows, bellow is my code. same code is working for static rows.
$('.dataGrid tr').bind('click', function(){
$('.dataGrid tr').removeClass('active');
$(this).addClass('active');
});
$('').appendTo(table)
.append($('').text(pos.posId))
.append($('').text(pos.posName))
.append($('').text(pos.posAddress));
please help me..
You need the live() method there instead of click for dynamically generated elements.
$('.dataGrid tr').live('click', function(){
$('.dataGrid tr').removeClass('active');
$(this).addClass('active');
});
Adding new rows to a table does not automatically add the event listener you need.
Create a function that does two things:
1. Add/insert a row to the table.
2. Bind the same event listener to that row, that you are binding to the static rows.

Resources