how to add dynamic data into grid in gwt with number of rows based on database records and columns 5 - gwt

Grid g=new Grid(arg0.size(),5);
g.setBorderWidth(5);
g.setTitle("users data");
g.setVisible(true);
g.setCellSpacing(3);
g.setCellPadding(2);
g.setText(0,0, "empid");
g.setText(0,1, "first name");
g.setText(0,2, "last name");
g.setText(0,3, "gender");
g.setText(0,4, "studies");
System.err.println("list = "+arg0);
for(int i=0;i<arg0.size();i++)
{
User data= (User) arg0.get(i);
for(int row=1;row<arg0.size();row++)
{
for(int col=0;col<5;col++)
{
g.setText(row, col,String.valueOf(data.getEmpid()));
g.setText(row, col,data.getFirstname());
g.setText(row, col, data.getLastname());
g.setText(row, col,data.getGender());
g.setText(row, col, data.getStudies());
}
}
}
RootPanel.get().clear();
RootPanel.get().add(g);
arg0 is list of User pojo. in every column the last field is only adding but we have to add appropriate data into each column. mostly i did wrong in for loop please correct me and give response

To add the data correctly, have the for-loop like this:
// make the grid the size of the userlist + 1 for the header line
Grid g = new Grid(arg0.size() + 1, 5);
// rest of the Grid-definition
;
// per user in the user-list, add one row
for(int i=0;i<arg0.size();i++){
// retrieve the current user
User data= (User) arg0.get(i);
// add the data of that user in the correct column
// concerning the row: add in currentRow+1 to compensate for header row
g.setText(i+1, 0,String.valueOf(data.getEmpid()));
g.setText(i+1, 1,data.getFirstname());
g.setText(i+1, 2, data.getLastname());
g.setText(i+1, 3,data.getGender());
g.setText(i+1, 4, data.getStudies());
}
However, another way would be using a CellTable. It is much more flexible than your Grid, you can easily add/remove rows, and it's much easier to e.g. change the order of the columns, should that be necessary some time in the future. Additionally, it provides interfaces for column sorting should that be necessary. If you're interested in seeing a CellTable example, let me know so that I can update this post.

Related

How to add rows to TableView without having any data model

I'm fairly new to javafx, so please bear with me if my question is unclear. I've a TableView which need to be populated using an ObservableList.
The code below populates my "data" with the arraylists generated out of the Map, which in turn is used to add rows to my table.
TableView<ArrayList> table = new TableView<>();
ObservableList<ArrayList> data = FXCollections.observableArrayList();
for(int i=0;i<listSelectedVerticesIds.size();i++){
ArrayList<String> tempString = new ArrayList<>();
for(Map.Entry<String,String> temp2 : mapVertex.get(listSelectedVerticesIds.get(i)).entrySet()){
tempString.add(temp2.getValue());
}
data.add(tempString);
}
table.setItems(data);
However, I do not see the table populated with the list in "data". I'm guessing this is because there is no data binding (using setCellValueFactory). However, as you can see I dont have a data model class. All of my data comes from the Map as strings which I would like to populate in my tableview.
Please suggest.
Here is a simple way to do it that works great. You don't need a data structure to populate a table. You only see that because that's what most examples show. It is an extremely common use case to populate a table from a database or a file. I don't understand why this is so hard to find examples for. Well, hope this helps.
private TableView<ObservableList<StringProperty>> table = new TableView<>();
private ArrayList<String> myList = new ArrayList<>();
private void updateTableRow() {
for (int row = 0; row < numberOfRows; row++) {
ObservableList<StringProperty> data = FXCollections.observableArrayList();
for (int column = 0; column < numberOfColumns; column++) {
data.add(column, new SimpleStringProperty(myList.get(row + (column * numberOfRows))));
}
table.getItems().add(data);
}
}

Reformatting spreadsheet responses into a new tab on form submit

Here are my spreadsheet responses from a form: https://docs.google.com/spreadsheets/d/1a9H2HqAwl29IY6-aCvCKs12Xb3vDcZHCOoNugx81PTA/edit#gid=1939572907
The form data generates in the "raw data" tab of the above spreadsheet. However, I'd like to automatically rearrange the form responses in a different format on the "teacher list" tab of the spreadsheet on form submissions. We are trying to keep track of how often we visit a teacher's room and so want all of the timestamps to appear next to the teacher's name.
I do not know if I should be using formulas or a script to get the job done.
To show you our end goal, I have two form submissions that I have typed into the cells where'd we like them to appear on the "teacher list" tab.
Any suggestions or resources to help me accomplish this would be very much appreciated!
This should give you a good start. And, I have removed the merging of the cells in G column in teacher list tab.
function myFunction() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Raw Data');
var data = sheet.getDataRange().getValues();
var formatSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Teacher List');
var formatData = formatSheet.getDataRange().getValues();
var name = data[sheet.getLastRow()-1][2];
var flag = 0, index;
for(var i=1; i<formatData.length; i++)
{
if(name == formatData[i][0])
{
flag = 1;
index = i;
break;
}
}
if(flag == 1)
{
for(var i=1; i<=5; i++)
{
if(formatData[index][i] == "")
{
formatSheet.getRange(index+1, i+1).setValue(data[sheet.getLastRow()-1][0]);
formatSheet.getRange(index+1, 7).setValue(formatData[index][6].concat('; '+data[sheet.getLastRow()-1][3]));
break;
}
}
}
}
But is there more than 5 visits possible? Is first column of teacher list tab is going to remian same throughout? Do you want to add new row if no match is found for 'Teacher or PLC Observed' from Raw Data with first column of Teacher List tab?
If answer to these questions is positive, you need to tweak a code little bit, try it. I'll help if you're stuck.
Edit: Please set the appscript trigger as: From form -> onSubmit.

GWT filler rows in a CellTable

I currently have a CellTable which I expanded with a filter/paging/sorting.
I am working on adding more features too.
One things that bugs me though, is when you set the limit for a page to be for example 10.
If an object doesn't have 10 rows and only has 5 and you switch between them then the table will jump up and down if positioned in the center.
Is there an elegant way, that when the pageSize is set to 10, then if there are less than 10 rows in a table, empty rows will be added?
The ways I have tried so far effect my filtering/sorting/paging, which I do not want.
EDIT 1:
final AsyncDataProvider<Row> provider = new AsyncDataProvider<Row>() {
#Override
protected void onRangeChanged(HasData<Row> display) {
int start = display.getVisibleRange().getStart();
int end = start + display.getVisibleRange().getLength();
end = end >= rows.getFilterList().size() ? rows.getFilterList().size() : end;
List<Row> sub = rows.getFilterList().subList(start, end);
System.out.println("Checking if extra rows needed: " +
table.getVisibleItems().size());
for(int i = table.getVisibleItems().size(); i<10; i++){
System.out.println("ADDED EMPTY ROW");
sub.add(new Row());
}
updateRowData(start, sub);
}
};
I had the same problem. I solved it by adding null rows. Basically, you need to override onRangeChange(HasData<T> display) in your DataProvider to add null to the list representing the range asked for. You add enough null to fill the range you want.
#Override
protected void onRangeChanged(HasData<T> display){
Range range = display.getVisibleRange();
List<T> listOfObjects = getRange(range);
for(int i=listOfObject.size(); i<range.getLength(); i++){
listOfObjects.add(null);
}
updateRowData(range.getStart(), listofObjects);
}
In the above code getRange() returns a list containing the objects that are requested (within the range)
You'll also have to add some CSS to give a height to rows. If you don't specify the height then the rows will be very small so they won't pad the whole table.
It's disappointing that GWT doesn't have support for this type of padding. This way was the best one that I found but unfortunately when your row heights differ within a table it makes everything harder.
Paging
With the solution above you'll need to have a custom Pager if you want paging. You can extend your AsyncDataProvider with method like getVisibleRowCount() this will return how many objects in the current sublist are actually real data (not null). Then you can give a reference of the AsyncDataProvider to the Pager and override the createText() method:
#Override
protected String createText(){
return getPageStart() + " - " + dataProvider.getVisibileRowCount() + " of "
+ dataProvider.getTotalRowCount();
}

How to compare two data rows in one data set in BIRT

I'm new to BIRT and need an answer to the following question:
How to compare two data rows in one data set in BIRT and then print it out to the document?
I am assuming you have a reason for not using a self-join query to bring in the data. One simple thing you could do is have 2 identical datasets and then create a new joint dataset using the 2.
With an Oracle DB, you could easily achieve this with pure SQL using the "Analytic Function" LAG (see the Oracle documentation for details).
Independent from the DB, with BIRT, you could use a variable last_row:
Create some computed columns to keep the results of your comparisons. e.g. "FIRST_COLUMN_CHANGED" as boolean.
afterOpen event:
last_row = null;
onFetch event (pls note I'm not sure wether the actual data columns start at 0 or 1):
if (last_row != null) {
if (last_row[0] == row[0]) {
row["FIRST_COLUMN_CHANGED"] = false;
} else {
row["FIRST_COLUMN_CHANGED"] = true;
}
} else {
// do computations for the first record.
row["FIRST_COLUMN_CHANGED"] = true;
}
// Copy the current row to last_row
last_row = {};
// modify depending on the number of columns
for (var i=0; i<10; i++) {
last_row[i] = row[i];
}

How can I receive the input of the changed fields in Vaadin?

My Vaadin application provides a little table, which is editable.
If the user - after changing some fields - clicks on the save button, I will receive all the rows and save the changed rows into the database.
// create a bean item container
val writers: BeanItemContainer[Person] = new BeanItemContainer[Person](classOf[Person])
// create some person objects
writers.addBean(new Person("Thomas", "Mann", 1929))
writers.addBean(new Person("W. B.", "Yeats", 1923))
writers.addBean(new Person("Günter", "Grass", 1999))
// create the table incl. the bean item container
val table: Table = new Table("Nobel Prize for Literature", writers)
// set some options for the table
table.setImmediate(true)
table.setEditable(true)
table.setValidationVisible(true)
// create the save button
val saveButton = new Button("save")
// create a table listener
saveButton.addListener(new Button.ClickListener() {
def buttonClick(event: com.vaadin.ui.Button#ClickEvent) {
table.commit()
val writerList = table.getItemIds.asInstanceOf[Collection[Person]].asScala.toList
//
// **THIS WILL NOT WORK**
//
// I received always the original rows, without the
// user input, but I needs the user input, the changed rows.
//
//
for (item <- writerList) {
println("firstName ====> " + item.getFirstName)
println("lastName =====> " + item.getLastName)
println("year==========> " + item.getYear)
}
}
});
How can I receive the changed rows with the user input? Is it necessary to implement a form? If yes, how I can implement a form in this case?
Vaadin does not keep track of modified items in a container. You have to track the modifications in your beans (Person). Define setters for all editable properties and set a modified flag if something changes. In the save button listener you can filter out all modified items.