AdvancedDataGrid GroupingField - apache-flex

need my AdvancedDataGrid group by the name of the person, but I'm having trouble because the groupingField not accept "objectPeople.idPeople"
the name of the groupingField not accept "objectPeople.idPeople"?
GroupingField name="people.idPeople" <--error??

That's because dot is not allowed in field handling.
Explanation.
Inside DataGrid addressing groupingField property from your item is held with square braces operator:
item[groupingField]
This addressing only supports one level. E.g. if you've got object inside object, you cannot address properties of the second one with square braces in first:
var outer:Object = new Object();
var inner:Object = new Object();
outer["property"] = inner;
inner["value"] = 0;
trace(outer["property.value"]); // runtime error
trace(outer.property.value); // traces 0
outer["property.value"] = 1; // creates property "property.value" in outer
trace(outer["property.value"]); // traces 1
trace(outer.property.value); // still traces 0
Answer.
If you have idPeople inside your item, you should specify groupingField="idPeople".
If you have objectPeople with idPeople property inside your item, you should (for instance) write a getter in your item to avoid multiple levels and specify its name in groupinf field property - groupingField="idPeople":
public function get idPeople():Number
{
return objectPeople.idPeople;
}
// ...
trace(item["idPeople"]); // works now

Related

Combine NSArrayController with NSTableview method "objectValueFor"

Can I use NSArrayController for my tableview , and using simultaneously this method : ?
func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any?
The idea behind:
I do not want to loose the benefits of the arraycontroller ( insert, update, delete ...) but I would like to have control on additional columns to display. The information inside these columns are calculated and formatted; values are coming from the array that the arraycontroller manages (Core Data).
I am afraid this is not possible because controller and tableviewfunction excludes each other ...
Thanks to Willeke, I got it made finally by using a extension for my entity.
extension ImportLog {
// Splits the imported lines into individual words
// For each entity, I split the property "line" .
// Later, in the objc computed property, I pick column number x
var splittedText:[String.SubSequence]{
return(self.line!.split(separator: ";"))
}
// col1
#objc var f1: String {
get {
let theColumn = 0
var text:String = ""
if ( splittedText.count-1 >= theColumn) {
text = String(splittedText[theColumn])
}
return text
}
set {
// no need to set something
}
}
}
The computed property "f1" of the entity can now be bound in the XIB file
by "Table Cell View.objectValue.f1"

javafx remove specific node from VBox

i have the following method:
CreateStrip createStrip = new CreateStrip(input);
depBox.getChildren().add(createStrip.getStripGrid());
depBox is a VBox and .getStripGrid() return a GridPane.
CreateStrip has this method too:
public String getNameStrip() { return input.getNameStrip();}
during the life of the program depBox get many GridPane, each one with a different NameStrip.
sometimes i have the necessity to remove a specific GridPane from depBox that match with .getNameStrip().
i have tried:
for (Node node: depBox.getChildren()) {
//TODO REMOVE GRIDPANE CONTAIN THE NAME THAT MATCH WITH THE MESSAGE RECEIVED..
}
but i don't know how to set the matching control.
Step 1:
Attach data to the GridPane that allows you to identify the one to remove.
You could do this by using Node.setUserData or by using the properties Map (which I'll do in the following code snippets).
Creating the GridPane
GridPane gp = createStrip.getStripGrid();
gp.getProperties().put(NAME_KEY, createStrip);
depBox.getChildren().add(gp);
// use object not equal to any other object as key (i.e. equals uses reference equality)
static final Object NAME_KEY = new Object();
Step 2:
Use the information to remove the appropriate GridPane. searchName is the String that identifies the GridPane you want to remove (to check for equality with getNameStrip()):
depBox.getChildren().removeIf(c -> {
CreateStrip strip = (CreateStrip) c.getProperties().get(NAME_KEY);
return strip != null && searchName.equals(strip.getNameStrip());
});
Depending on your CreateStrip class it may not be necessary to add a instance of it as property. It may not even be the right thing to do, if it's a factory, but I think you get the idea nontheless.
Alternative
You can also assign a value to the id property of the Node and use those to identify the correct node using Node.lookup. However those need to be unique and be a valid css id, but you could use a Map to map from message to id.

Ensure Spark DataGrid item is visible

Is there a way to make sure the selected item is visible in the Spark DataGrid?
.
Context
I have a data grid bound to an array collection. I receive remotely a service that gives me a ID (string) of an object that is in the collection. Using just the string I loop through the collection to find the item that matches the string. I find the object by it's ID. Now I have the object I want to select in the datagrid. I can set the
dataGrid.selectedItem = object;
Now I need to make sure it's visible. I do not have the row or column index.
.
Update
Using the answer below I've complimented it with this function:
/**
* Ensures the item is visible (for spark data grid)
**/
public function ensureItemIsVisibleInSparkDataGrid(datagrid:spark.components.DataGrid, item:Object):void {
var list:IList = datagrid.dataProvider;
var length:int = list.length;
var itemFound:Boolean;
var object:Object;
var index:int;
for (var i:int;i<length;i++) {
object = list.getItemAt(i);
if (object==item) {
itemFound = true;
index = i;
break;
}
}
if (itemFound) {
datagrid.ensureCellIsVisible(index);
}
}
Yes, it's called ensureCellIsVisible(). You need to know that row and column of the item in question. To get this to work you'd need to listen for the selectionChange event then calculate the row and column of the currently selected item.

GXT -coloring entire grid row according to one cell in row

. .
I colored one column according to the value of cell but i want to color the entire row (means the cell contained row ) in gxt grid help me
here is my code for coloring the cell (i want to color the row instead of the cell)
/*------------Coloring Area------------*/
GridCellRenderer<BeanModelType> ColoredGrid = new GridCellRenderer<BeanModelType>() {
#Override
public Object render(BeanModelType model,
String property, ColumnData config,
int rowIndex, int colIndex,
ListStore<BeanModelType> store,
Grid<BeanModelType> grid) {
String valueOfCell = model.get(property);
String style = valueOfCell.equals("Book") ? "GREEN":
valueOfCell.equals("Ersr") ? "red":
valueOfCell.equals("Pen") ? "yellow":
valueOfCell.equals("comp") ? "blue": "";
//Config is the cell and we are setting style here
config.style ="background-color:"+style;
return valueOfCell;
}
};
System.out.println("COLORRRRR "+cleanColoredGrid.toString());
column.setRenderer(ColoredGrid);
/*-------------Coloring Area Ends-------*/
configs.add(column);
Given you are using GXT > 2.x.x, the correct way to do this is to attach a new GridViewConfig to your grid's view.
You should probably do something like:
grid.getView().setViewConfig(new GridViewConfig() {
#Override
public String getRowStyle(ModelData model, int rowIndex, ListStore<ModelData> ds) {
if (model != null) {
//TODO: put your conditions here
if ("YOUR_CONDITION".equals(model.get("BOOK_COLOR))) {
return "green-row";
}
}
return "";
}
});
You should amend your css accordingly. (note that green-row is a name of a css style class).
See this for reference: http://www.jarvana.com/jarvana/view/com/extjs/gxt/2.1.1/gxt-2.1.1-javadoc.jar!/gxt-2.1.1-javadoc/com/extjs/gxt/ui/client/widget/grid/GridViewConfig.html
In every render method you got model as one of parameter, so try to set the same renderer to each column, but replace 'property' to name of attribute which holds string with type of item. Let's suppose you called it 'itemName', so change your code to:
model.get("itemName");
Maybe casting will be required, because model.get() should return Object.
Now in every column the same check will be performed and all of them should be in one color.
If that will work, next step could be some optimizations: if first check returns some color, set it into hashmap of model-to-color (or into the model directly as a new attribute) and add in the renderer a condition which will check if color wasn't already assigned.

datagrid cannot be found

I create each datagrid to be added to the NavigatorConent(), however, how do I retrieve the datagrid by ID so that I can point the ArrayCollection to datagrid's dataprovider?
private var pdg:String;
private function stabAdd():void {
var dg1:DataGrid = new DataGrid();
var cn:NavigatorContent = new NavigatorContent();
stab.addElement(cn);
cn.name = "nc"+nu;
dg1.id = "nc"+nu;
pdg = dg1.id;
dg1.addEventListener(MouseEvent.CLICK,cc);
nu++;
This will throw an error which pdg cannot be found, I wonder why:
trace(DataGrid(pdg));
The purpose of nu++ is to assign a
unique name (dg1, dg2, etc) to each
datagrid so that I can assign AC to
that datagrid's dataprovider
I can respect the need to give every component a unique name. The appropriate way to do that in ActionScript is not to specify the id/name field of the component, but rather to create an instance of the component as a variable. Something like this:
protected var myGrid : DataGrid;
And you can now access myGrid anywhere in the component, or in it's children, without creating some complicated scheme. If you need multiple DataGrid's you can store them in an array:
protected var myGridArray : Array = new Array();
And somewhere later in your code--probably createChildren() do something like this:
loop
var newGrid : DataGrid = new DataGrid()
myGridArray.push(newGrid);
end loop
For the most part, this is how all the Flex list based components do it with itemRenderers. They have an array of visible renderers.
As stated in #J_A_X_ comments, you are trying to convert pdg--a string--into a DataGrid. I would expect that to return a null value, as Flex casts tend to fail quietly.
If you want more help, you'll have to tell us the explicit error that you're receiving, possibly with line numbers and more code.

Resources