How to add a dynamic content in tabular format using repeater in Wicket - wicket

I am new to Wicket and am trying to add purely dynamic content in wicket.
I have a list of object TableDataValuesVO which has a String tableName and a map columnNamesAndValues (containing columnName And its value). Each object in the list represent different data records of different table (the size of columnNameAndValues differ for each object). As of now I am using repeatingview for columnName and Value.but it displays one columnName per row and below that one columnValue per row.
Class to generate this component:
Html:
<table wicket:id="applicationDataView">
Java:
boolean columnNameRendered = false;
applicationDataView = new RepeatingView("applicationDataView")
RepeatingView tableView = new RepeatingView(applicationDataView.newChildId());
RepeatingView columnNameView = new RepeatingView(applicationDataView.newChildId());
tableView.add(new Label(applicationDataView.newChildId(),tableName));
applicationDataView.add(columnNameView);
applicationDataView.add(tableView);
List<dataVO> dataForTable= applicationDataByTable.get(tableName);
for (DataVO dataVO: dataForTable)
{
RepeatingView columnValueView= new RepeatingView(applicationDataView.newChildId());
if (!columnNameRendered)
{
for (String columnName : dataVO.getColumnNamesAndValues().keySet())
{
columnNameView.add(new Label(tableName+columnName,columnName));
}
columnNameRendered = true;
}
for (String columnName : dataVO.getColumnNamesAndValues().keySet())
{
String columnValue = tableDataValuesForRecordVO.getColumnNamesAndValues().get(columnName);
columnValueView.add(new Label(applicationDataView.newChildId(),columnValue));
applicationDataView.add(columnValueView);
}
}
Actual result:
Table name1:
Column 1
Column 2
Column 3
Val11
Val12
....
Table name2:
Column 1
Column 2
Column 3
Column 4
Val11
Val12....
Expected Result:
Table Name1:
Col1 col2 Col3
val11 val12 val13
val21 val22 val23
Table Name2:
Co131 col32 Col33 col34
val11 val12 val13 val14
val21 val22 val23 val24
Please help in providing a solution to display the dynamic data?

You can use, for example, a ListView that draws a lot of DataTables. (side note:I think this will be not very fast, as you will generate loads of HTML. )
Java:
List<DataVo> dataVoList = ... //create your list of datavo's
add(new ListView<DataVo>("listview", dataVoList) {
protected void populateItem(ListItem<DataVo> item) {
DataVo dataVo = (DataVo) item.getModelObject();
final DataProvider dataProviderBasedOnVo = ... //create dataprovider here.
IColumn[] columns = ... //create columns here, based on the dataVo
item.add(new DataTable("table", columns, dataProviderBasedOnVo, 10));
}
});
HTML:
...
<div wicket:id="listview">
<table wicket:id="table"></table>
</div>
...

Related

Repeat the columns using data-sly-repeat based on the number entered in the cq dialog. Columns are not repeating

I want to repeat the parsys in the columns based on the number of columns added in cq dialog. I can only get one column and the numbers of columns as entered
<div class="items">
<div data-sly-repeat="${grid.cols}" class="col col-lg-4 col-md-2 pt-2 pb-2">
<div data-sly-resource="${'content-{0}' # format=[colList.index], resourceType='wcm/foundation/components/parsys'}"></div>
</div>
</div>
</div>
carousel.js:
"use strict";
use(function() {
var properties = granite.properties,
colCount = properties.numberofcolumns ? properties.numberofcolumns : 3,
cols = '';
return {
"cols" : colCount
};
});
data-sly-repeat expects a list, not a number. You're only returning the number of columns. If you return an n-element list, data-sly-repeat will render an element for each item in the list.
It's a bit of a hack but in your carousel.js, you'd have to return an array with a list of values. The primary use case of data-sly-repeat (and data-sly-list) is to iterate over the elements of a collection returned by the underlying Java/JS code and output the properties of each item in the list. In your case, the only difference between the repeated div elements is the index.
use(function() {
var properties = granite.properties,
colCount = properties.numberofcolumns ? properties.numberofcolumns : 3;
var resultList = [];
for (var i = 0 ; i < colCount ; i++) {
resultList.push(i);
}
return {
"cols" : resultList // data-sly-repeat expects a collection
};
});
On a more general note, it seems what you're aiming to do is to include a bunch of paragraph systems by name to achieve some sort of column layout. Before attempting this, I would consider using the OOTB Layout Container component, which can be resized in Edit mode to fit any number of columns without any new development.

Defining data type of a Google Charts DataTable column after it has been created

I am a newbie of Google charts. I am trying to change data type of a google chart data table column after this has been created. Searching for a solution over the internet I have bumped into this solution for a datetype column. May you generalize it in order to change a chosen data type column from number to string? I would like to change it so that I can visualize some strings in a number column, as you can see in the attached screenshot.
My trial is:
<script type="text/javascript">
function drawVisualization() {
$.get("delivery_pl_daily_test.csv", function(csvString) {
// transform the CSV string into a 2-dimensional array
var arrayData = $.csv.toArrays(csvString, {onParseValue: $.csv.hooks.castToScalar});
// this new DataTable object holds all the data
var data = new google.visualization.arrayToDataTable(arrayData);
var columns = [];
for (var i = 0; i < data.getNumberOfColumns(); i++) {
columns.push(i);
}
var view = new google.visualization.DataView(data);
columns[0] = {
calc: row,
label: arrayData[0][0],
type: 'string'
};
view.setColumns(columns);
Thanks in advance.
Drigo
what you have looks close,
but calc should be a function,
that returns the value for the column.
the calc function receives the data table and current row as arguments.
here, I simply return the formatted value of the column.
columns[0] = {
calc: function (dt, row) {
return dt.getFormattedValue(row, 0);
},
label: arrayData[0][0],
type: 'string'
};

Bulk Operations - Adding multiple rows to sheet

I'm attempting to write data from a data table to a sheet via the smartsheet API (using c# SDK). I have looked at the documentation and I see that it supports bulk operations but I'm struggling with finding an example for that functionality.
I've attempted to do a work around and just loop through each record from my source and post that data.
//Get column properties (column Id ) for existing smartsheet and add them to List for AddRows parameter
//Compare to existing Column names in Data table for capture of related column id
var columnArray = getSheet.Columns;
foreach (var column in columnArray)
{
foreach (DataColumn columnPdiExtract in pdiExtractDataTable.Columns)
{
//Console.WriteLine(columnPdiExtract.ColumnName);
if(column.Title == columnPdiExtract.ColumnName)
{
long columnIdValue = column.Id ?? 0;
//addColumnArrayIdList.Add(columnIdValue);
addColumnArrayIdList.Add(new KeyValuePair<string, long>(column.Title,columnIdValue));
}
}
}
foreach(var columnTitleIdPair in addColumnArrayIdList)
{
Console.WriteLine(columnTitleIdPair.Key);
var results = from row in pdiExtractDataTable.AsEnumerable() select row.Field<Double?>(columnTitleIdPair.Key);
foreach (var record in results)
{
Cell[] cells = new Cell[]
{
new Cell
{
ColumnId = columnTitleIdPair.Value,
Value = record
}
};
cellRecords = cells.ToList();
cellRecordsInsert.Add(cellRecords);
}
Row rows = new Row
{
ToTop = true,
Cells = cellRecords
};
IList<Row> newRows = smartsheet.SheetResources.RowResources.AddRows(sheetId, new Row[] { rows });
}
I expected to generate a value for each cell, append that to the list and then post it through the Row Object. However, my loop is appending the column values as such: A1: 1, B2: 2, C3: 3 instead of A1: 1, B1: 2, C3: 3
The preference would be to use bulk operations, but without an example I'm a bit at a loss. However, the loop isn't working out either so if anyone has any suggestions I would be very grateful!
Thank you,
Channing
Have you seen the Smartsheet C# sample read / write sheet? That may be a useful reference. It contains an example use of bulk operations that updates multiple rows with a single call.
Taylor,
Thank you for your help. You lead me in the right direction and I figured my way through a solution.
I grouped by my column value list and built records for the final bulk operation. I used a For loop but the elements in each grouping of columns is cleaned and assigned a 0 prior to this method so that they retain the same count of values per grouping.
// Pair column and cell values for row building - match
// Data source column title names with Smartsheet column title names
List<Cell> pairedColumnCells = new List<Cell>();
//Accumulate cells
List<Cell> cellsToImport = new List<Cell>();
//Accumulate rows for additions here
List<Row> rowsToInsert = new List<Row>();
var groupByCells = PairDataSourceAndSmartsheetColumnToGenerateCells(
sheet,
dataSourceDataTable).GroupBy(
c => c.ColumnId,
c => c.Value,
(key, g) => new {
ColumnId = key, Value = g.ToList<object>()
});
var countGroupOfCells = groupByCells.FirstOrDefault().Value.Count();
for (int i = 0; i <= countGroupOfCells - 1; i++)
{
foreach (var groupOfCells in groupByCells)
{
var cellListEelement = groupOfCells.Value.ElementAt(i);
var cellToAdd = new Cell
{
ColumnId = groupOfCells.ColumnId,
Value = cellListEelement
};
cellsToImport.Add(cellToAdd);
}
Row rows = new Row
{
ToTop = true,
Cells = cellsToImport
};
rowsToInsert.Add(rows);
cellsToImport = new List<Cell>();
}
return rowsToInsert;

How to add item or value in assigned list to var?

I tried many ways but couldn't get the solution.
// linq query to getting 3 fields from table
var listData = (from row in db.table
orderby row.No ascending
select new {
row.Id,
row.No,
row.Type
}).ToList();
I want to add item or value to listData.
try Code:
var listData = (from row in db.table
select new
{
Id= row.Id,
No= row.No,
Type= row.Type
}
).OrderBy(c=>c.No).ToList();

Fetching Cassandra row keys

Assume a Cassandra datastore with 20 rows, with row keys named "r1" .. "r20".
Questions:
How do I fetch the row keys of the first ten rows (r1 to r10)?
How do I fetch the row keys of the next ten rows (r11 to r20)?
I'm looking for the Cassandra analogy to:
SELECT row_key FROM table LIMIT 0, 10;
SELECT row_key FROM table LIMIT 10, 10;
Take a look at:
list<KeySlice> get_range_slices(keyspace, column_parent, predicate, range, consistency_level)
Where your KeyRange tuple is (start_key, end_key) == (r1, r10)
Based on my tests there is no order for the rows (unlike columns). CQL 3.0.0 can retrieve row keys but not distinct (there should be a way that I do not know).I my case I do not know what my key range is, so I tried to retrieve all the keys with both Hector and Thrift, and sort the keys later. The performance test with CQL 3.0.0 for 100000 columns 200 rows was about 500 milliseconds, Hector around 100 and thrift about 50 milliseconds. My Row key here is integer. Hector code follows:
public void queryRowkeys() {
myCluster = HFactory.getOrCreateCluster(CLUSTER_NAME, "127.0.0.1:9160");
ConfigurableConsistencyLevel ccl = new ConfigurableConsistencyLevel();
ccl.setDefaultReadConsistencyLevel(HConsistencyLevel.ONE);
myKeyspace = HFactory.createKeyspace(KEYSPACE_NAME, myCluster, ccl);
RangeSlicesQuery<Integer, Composite, String> rangeSlicesQuery = HFactory.createRangeSlicesQuery(myKeyspace, IntegerSerializer.get(),
CompositeSerializer.get(), StringSerializer.get());
long start = System.currentTimeMillis();
QueryResult<OrderedRows<Integer, Composite, String>> result =
rangeSlicesQuery.setColumnFamily(CF).setKeys(0, -1).setReturnKeysOnly().execute();
OrderedRows<Integer, Composite, String> orderedRows = result.get();
ArrayList<Integer> list = new ArrayList<Integer>();
for(Row<Integer, Composite, String> row: orderedRows){
list.add(row.getKey());
}
System.out.println((System.currentTimeMillis()-start));
Collections.sort(list);
for(Integer i: list){
System.out.println(i);
}
}
This is the Thrift code:
public void retreiveRows(){
try {
transport = new TFramedTransport(new TSocket("localhost", 9160));
TProtocol protocol = new TBinaryProtocol(transport);
client = new Cassandra.Client(protocol);
transport.open();
client.set_keyspace("prefdb");
ColumnParent columnParent = new ColumnParent("events");
SlicePredicate predicate = new SlicePredicate();
predicate.setSlice_range(new SliceRange(ByteBuffer.wrap(new byte[0]), ByteBuffer.wrap(new byte[0]), false, 1));
KeyRange keyRange = new KeyRange(); //Get all keys
keyRange.setStart_key(new byte[0]);
keyRange.setEnd_key(new byte[0]);
long start = System.currentTimeMillis();
List<KeySlice> keySlices = client.get_range_slices(columnParent, predicate, keyRange, ConsistencyLevel.ONE);
ArrayList<Integer> list = new ArrayList<Integer>();
for (KeySlice ks : keySlices) {
list.add(ByteBuffer.wrap(ks.getKey()).getInt());
}
Collections.sort(list);
System.out.println((System.currentTimeMillis()-start));
for(Integer i: list){
System.out.println(i);
}
transport.close();
} catch (Exception e) {
e.printStackTrace();
}
}
You should firstly modify cassandra.yaml in the version of cassandra1.1.o, where you should set as follows:
partitioner: org.apache.cassandra.dht.ByteOrderedPartitioner
Secondly,you should define as follows:
create keyspace DEMO with placement_strategy =
'org.apache.cassandra.locator.SimpleStrategy' and
strategy_options = [{replication_factor:1}];
use DEMO;
create column family Users with comparator = AsciiType and
key_validation_class = LongType and
column_metadata = [
{
column_name: aaa,
validation_class: BytesType
},{
column_name: bbb,
validation_class: BytesType
},{
column_name: ccc,
validation_class: BytesType
}
];
Finally, you can insert data into cassandra and can realize range query.