Programmatically create polymer Elements in Dart - dart

Need add polymer paper-dropdown-menu in DOM.
I try this code:
makePapersElements() {
List _items = new List();
for (var i = 0; i < 13; i++) {
PaperItem item = new dom.Element.tag('paper-item');
item.text = i;
_items.add(item);
}
return _items;
}
And add nodes in PaperListbox then in PaperDropdownMenu:
List<PaperItem> items = makePapersElements();
var element = new dom.Element.tag('div');
PaperDropdownMenu dropMenu = new PaperDropdownMenu();
PaperListbox listBox = new dom.Element.tag('paper-listbox');
dropMenu.append(listBox);
listBox.nodes.addAll(items);
element.nodes.add(dropMenu);
$['example'].nodes.add(element);
It's not work currently:
How it can be done?
Update: Added Gist
https://gist.github.com/Rasarts/a0b6710e234ec8b4aa37f90e4cd14839

You can create PaperDropDownMenu and Paperlistbox with new Xxx(), no need for new dom.Element.tag('Xxx') because these elements contain a constructor for convenience where this is done already
https://github.com/dart-lang/polymer_elements/blob/7912e0e6641155505007a89140f11c25db14e3f8/lib/paper_listbox.dart#L61
https://github.com/dart-lang/polymer_elements/blob/7912e0e6641155505007a89140f11c25db14e3f8/lib/paper_dropdown_menu.dart#L69
I guess the issue is because you don't use the Polymer DOM API. See also https://github.com/dart-lang/polymer-dart/wiki/local-dom. Only when you enable full shadow DOM (with full polyfills whithout native support) then you don't need to use this API.
makePapersElements() {
List _items = new List();
for (var i = 0; i < 13; i++) {
PaperItem item = new PaperItem();
item.text = i;
_items.add(item);
}
return _items;
}
List<PaperItem> items = makePapersElements();
var element = new dom.Element.tag('div');
PaperDropdownMenu dropMenu = new PaperDropdownMenu();
PaperListbox listBox = new PaperListbox();
Polymer.dom(dropMenu).append(listBox);
// not sure this will work
Polymer.dom(listBox).childNodes.addAll(items);
// alternatively
var listboxDom = Polymer.dom(listBox);
for(var item in items) {
listboxDom.append(item);
}
Polymer.dom(this)appen(dropMenu);
// ro Polymer.dom(this.root)appen(dropMenu);
Polymer.dom($['example']).append(element);

Yes, I do it wrong. Example helped. Thanks.
https://github.com/bwu-dart-playground/polymer1/blob/12a4bca9c5c5b21c690af0bd4451407b64899a6e/so36689312_programmatically_create_paper_elements/web/pdm_element.dart#L36-L36

Related

c# how to add multiple RDT segments on NHapi using HL7 version 2.5.1

I'm working with nHapi v2.5.0.6 and I'm trying to create multiple RDT segments for HL7 v2.5.1.
The segments should look like this:
RDT|555444222111|Adam||19600614|M|
RDT|555444222112|Adam2||19600615|F|
RDT|555444222113|Adam3||19600616|M|
But the most I can do, is this:
RDT|555444222111
RDT|555444222112
RDT|555444222113
I don't know how to add fields after the first one!
This is my code:
private void addSegmentRDT2(DataTable informationTable)
{
//RDT|555444222111|||19600614|M|
var tbr_r08 = new TBR_R08();
int rowNumber = 0;
foreach (DataRow row in informationTable.Rows)
{
var RTD = tbr_r08.AddRDT();
int columnNumber = 0;
foreach (DataColumn column in informationTable.Columns)
{
NHapi.Model.V23.Datatype.ST a = new NHapi.Model.V23.Datatype.ST(tbr_r08.Message);
a.Value = row[column]?.ToString() ?? "";
RTD.ColumnValue.Data = a;
}
}
}
Any help will be appreciated.
Thanks
This is how I resolve the problem, is not the most elegant solution but it works :).
private void addSegmentRDT(DataTable informationTable)
{
var rowNumber = 0;
var tbr_r08 = new TBR_R08();
foreach (DataRow row in informationTable.Rows)
{
var RTD = tbr_r08.AddRDT();
var values = new Varies(tbr_r08.Message);
var columnNumber = 0;
foreach (DataColumn column in informationTable.Columns)
{
var rowColumnValue = row[columnNumber]?.ToString() ?? "";
var HL7String = new NHapi.Model.V23.Datatype.ST(tbr_r08.Message);
HL7String.Value = rowColumnValue;
values.ExtraComponents.getComponent(columnNumber).Data = HL7String;
++columnNumber;
}
RTD.ColumnValue.Data = values;
++rowNumber;
}
}

BwuDatagrid and PaperDropdownMenu like a field editor

I try add custom editor for BwuDatagrid in newInstance I tried to write:
PaperDropdownMenu dropMenu = new dom.Element.tag('paper-dropdown-menu');
PaperListbox listBox = new dom.Element.tag('paper-listbox');
makePapersElements(){
List _items = new List();
for (var i = 0; i < 13; i++){
PaperItem item = new dom.Element.tag('paper-item');
item.text = i;
_items.add(item);
}
return _items;
}
List<PaperItem> items = makePapersElements();
listBox.children.addAll(items);
dropMenu.append(listBox);
args.container.append(dropMenu);
listBox.selected = 2;
But i have got wrong structure:
Then I try:
args.container.appendHtml(
''' <paper-material>
<paper-dropdown-menu class='dropdown-menu'>
<paper-listbox class="dropdown-content">
</paper-listbox>
</paper-dropdown-menu>
</paper-material>''',
treeSanitizer: new NullTreeSanitizer());
PaperDropdownMenu menu = dom.querySelector('paper-dropdown-menu');
PaperListbox listbox = menu.querySelector('paper-listbox');
listbox.nodes.addAll(makePapersElements());
listbox.selected = 8;
With treeSanitizer:
class NullTreeSanitizer implements dom.NodeTreeSanitizer {
void sanitizeTree(node) {}
}
It's works, but position of selected element not in focus.
And scrollTop does not work too:
listbox.scrollTop = 120;
How I can focus selected element in paper-dropdown-menu?

How to check a kendo ui treeview child nodes based upon a kendo ui grid data

On an asp.net mvc page, I have a Kendo UI grid and a Kendo UI treeview. The treeview has checkboxes and the treeview has two tier data. Then once the grid is populated, I want to loop through the rows, find the corresponding id, then loop through the treeview and find the node with the same id and make it checked. The following is my code:
Grid code:
dataBound: function () {
var rows = this.tbody.children();
var dataItems = this.dataSource.view();
for (var i = 0; i < dataItems.length; i++) {
kendo.bind(rows[i], dataItems[i]);
bindCheckboxToId(dataItems[i].ID);
}
}
The javascript function to set the treeview node to be checked:
function bindCheckboxToId(id) {
var treeView = $("#treeview").data("kendoTreeView");
var myNodes = treeView.dataSource.view();
for (var i = 0; i < myNodes.length; i++) {
var children = myNodes[i].children.view();
alert(children.length);
if (children) {
for (var j = 0; j < children.length; j++) {
if (children[j].id === id) {
children[j].set("checked", true);
}
}
}
}
The problem is that, the children.length always comes as 0, although each parent node has two child nodes.
Thanks
We have to force the tree view to load the child nodes. The following is the updated code:
function bindCheckboxToId(id) {
var treeView = $("#treeview").data("kendoTreeView");
var myNodes = treeView.dataSource.view();
for (var i = 0; i < myNodes.length; i++) {
myNodes[i].load();
var children = myNodes[i].children.view();
//alert(children.length);
if (children) {
for (var j = 0; j < children.length; j++) {
if (children[j].id === id) {
children[j].set("checked", true);
}
}
}
}
}

smartgwt listgrid.getRecordList() not give me updated data

I'm on my smartgwt project having issue in listgrid.
my listgrid having data come from server side, and user allow to edit any record from that grid.
searchGrid.setAutoFetchData(true);
searchGrid.setDataSource(searchDS);
searchGrid.setAlwaysShowEditors(true);
When I try to edit any cell in grid and try to loop through all record from grid, it doesn't give me latest updated cell which I edited.
I use below code for fetching all records from my listgrid.
private String getGridDetails() {
RecordList records = searchGrid.getRecordList();
Document doc = XMLParser.createDocument();
Element rootElement = doc.createElement("ROOT");
doc.appendChild(rootElement);
for (int i = 0; i < records.getLength(); i++) {
Record rec = records.get(i);
Element row = doc.createElement("ROW");
for (String str : rec.getAttributes()) {
String propertyVal = rec.getAttributeAsString(str);
if (propertyVal != null
&& propertyVal.equalsIgnoreCase("") != true) {
Element columnElement = doc
.createElement(str.toUpperCase());
columnElement.appendChild(doc.createTextNode(propertyVal));
row.appendChild(columnElement);
}
}
rootElement.appendChild(row);
}
return doc.toString();
}
If you want to get every edited and unedited record, you may loop one by one:
public Record[] getData(ListGrid grid)
{
RecordList data = new RecordList();
for (int i = 0; i < grid.getTotalRows(); i++)
data.add(grid.getEditedRecord(i));
return data.duplicate();
}
But if you just want to retrieve the edited records, try the following snippet:
public static Record[] dameDatosLocalesEditedRows(ListGrid grid)
{
RecordList data = new RecordList();
int[] edited = grid.getAllEditRows();
for (int i = 0; i < edited.length; i++)
data.add(grid.getEditedRecord(edited[i]));
return data.duplicate();
}

My DropDownListFor does not select the SelectedValue from my SelectList

My DropDownListFor does not select the SelectedValue from my SelectList, it always selected the first item instead. Any solution?
hmm, actually, on second thought, double check sublegerType_Id? I'm not sure it should be the Id. I think it needs to be the actual object.
for example, this doesnt work (it defaults to the first item)
List<Tuple<string, string>> NumberList = new List<Tuple<string, string>>();
for (int i = 0; i < 5; i++)
{
NumberList.Add(new Tuple<string, string>(i.ToString(),i.ToString()));
}
NumberSelectList = new SelectList(NumberList,"2");
but this works okay (it defaults to the selected item of (4,4))
List<Tuple<string, string>> NumberList = new List<Tuple<string, string>>();
Tuple<string, string> selectedObject = new Tuple<string, string>("-1","-1");
for (int i = 0; i < 5; i++)
{
if (i == 4)
{
selectedObject = new Tuple<string, string>(i.ToString(), i.ToString());
NumberList.Add(selectedObject);
}
else
NumberList.Add(new Tuple<string, string>(i.ToString(), i.ToString()));
}
NumberSelectList = new SelectList(NumberList, selectedObject);

Resources