Combine NSArrayController with NSTableview method "objectValueFor" - nstableview

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"

Related

Pipe and underline between ea number

so i have a number lets say 19356 i want it to look like 1|9|3|5|6 and it also to all be underlined. Is this possible without breaking the number and adding a pipe and underline? Also it doesn't have to be a pipe as such just a line between the numbers.
I have a solution your problem. You can achieve it by extending sap.m.FormattedText and handling the functionality as we need as follows.
I will create two files with name SpecialFormattedText and SpecialFormattedTextRenderer as below.
Here is first class that extends FormattedText and has one property number of type int, because you wanted to work with numbers So I choose the int data type.
sap.ui.define(["sap/m/FormattedText"], function (FormattedText) {
"use strict";
return FormattedText.extend("SpecialFormattedText", {
metadata : {
properties : {
number : {
type : "int", defaultValue : null
}
}
},
setNumber : function(iMumber) {
this.setProperty("number", iMumber, true);
this.setProperty("htmlText", this._getUpdatedNumber(iMumber), true);
},
_getUpdatedNumber : function(iMumber) {
return "<U>"+iMumber.toString().match(/.{1}/g).join('|')+"</U>";
}
});
});
Here I will convert the input as we required and setting to the htmlText of FormattedText and maintaining the original value in number. And you can get the original value by using getNumber method provided by SpecialFormattedText class object.
And the next important thing is we are writing the renderer in other class named SpecialFormattedTextRenderer. In this class we will just call the sap.m.FormattedTextRenderer class renderer method as below.
sap.ui.define(["sap/m/FormattedTextRenderer"], function (FormattedTextRenderer) {
"use strict";
var SpecialFormattedTextRenderer = {};
SpecialFormattedTextRenderer.render = function (oRM, oControl) {
oRM.write("<div");
FormattedTextRenderer.render(oRM, oControl);
oRM.write("</div>");
};
return SpecialFormattedTextRenderer;
},true);

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.

How to update content in Row after selection in dojo datagrid

I have created one dojo datagrid. Every column has a formatter attached to it. When grid is generated the formatter is called. Now I want it so that if a user selects any row the formatter will be called and some strings should be attached to the selected row's column element.
Like grid is like this :
COLUMN
-------
a
b
c
and now user selects the 2nd row, the grid should change to :
COLUMN
-------
a
b SELECTED
c
Currently I implemented it like this :
if(this.grid.selection.selectedIndex !== -1){
retrun value + "SELECTED";
}else{
return value;
}
Can you please suggest a some good way of doing this? Please note that "SELECTED" string should not be added to the grid store.
The formatted is not hooked into clicking / selection of rows. It is solely performed when the contents (value) of a cell is set. Instead you'd want to move focus over to onRowClicked - an event on the grid component. It works like this:
grid.onRowClick = onRowClickHandler;
I wouldnt know which of following samples would put you closest to your goal but onRowClickHandler could be setup as such:
function onRowClickHandler(evt) {
var rows = this.selection.getSelected();
// perform cell rendering here
dojo.forEach(rows, function(row) {
// this row is an item though.. you will have row._O as its index
});
}
OR
function onRowClickHandler(e) {
var cellClicked = this.focus.cell
cellClicked.formatter();
}
However you may find that there are not much references to the viewable data anywhere in the grid component.. You could use following query selectors to find cell data and update the viewed html by calling formatter on each value. You would need to capture a previous selection for 'teardown' of your custom setting of values though.
var prevSelectedRows = [];
function onRowClickHandler(evt) {
var idx = this.selection.selectedIndex,
rawRow = dojo.query(".dojoxGridRow:nth-child("+(idx+1)+")", this.domNode)[0],
self = this;
// perform resetting of viewable values
dojo.forEach(prevSelectedRows, function(raw) {
dojo.query('.dojoxGridCell', raw).forEach(function(cellDOM, i) {
cellDOM.innerHTML = cellDOM.innerHTML.replace("SELECTED", "");
});
});
prevSelectedRows = []; // reset prev selection
// look into grid.view.content for methods on this
// perform setting of viewable values (SELECTED)
dojo.query('.dojoxGridCell', rawRow).forEach(function(cellDOM, i) {
// this function might be of interest, lets see how it looks in console
console.log(self.layout.cells[i].formatter);
cellDOM.innerHTML = cellDOM.innerHTML + "SELECTED"
});
prevSelectedRows.push(rawRow);
}

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.

AdvancedDataGrid GroupingField

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

Resources