DevExpress set focus to specific row of VerticalGrid - devexpress-windows-ui

My code to set the focus to a specific row of the VerticalGrid is not working.
this.ActiveControl = vGridControl1;
vGridControl1.Focus();
vGridControl1.FocusedRow = vGridControl1.GetRowByFieldName("addr1");
I have confirmed that vGridControl1.GetRowByFieldName("addr1") returns the correct row.
The first row contains a ButtonEdit, and that is where focus always goes.
The grid is in MultiRecordView but at this point contains only one (new) blank record. Adding
vGridControl1.FocusedRecord = 0;
before setting the FocusedRow doesn't make a difference.
What step am I overlooking?

Try using this which worked for me...
vGrdSummary.Focus()
vGrdSummary.FocusedRow = vGrdSummary.Rows("rowNatureOfLoss")

Related

Problem adding new child row to parent row; new row always added to bottom of sheet

I'm trying to add a new indented row as a child of an existing row and it just adds a new row to the bottom of the sheet instead of indented underneath parent row.
new_row = ssc.models.Row()
new_row.cells.append({
'column_id':5050181304510340,
'parentId':1379272254089092,
'strict':False,
'value':"test_value",
})
response = ssc.Sheets.add_rows(6110498509875076, [new_row])
Thanks for any help.
Seems like you have a typo in one of the property names. Try changing parentId to parent_id instead.
Also worth mentioning that the Specify Row Location section of the docs contains some good info about how to set various row properties to specify row position. (Mentioning this here mainly for the benefit of others who may find this thread later while looking for info about row positioning).
OMFG...been working for 2 days trying to return the parent and sibling and turns out it's a typo in the docs. This post is $$$
print(row.parent_id)
print(row.sibling_id)
print(row.row_number)

ag-grid: Using Drag drop to reorder rows within the grid

I need to re-order rows within ag-grid by using drag-drop. The drag drop methods are simple enough but when the drop occurs there seems no easy way to switch the rows locations.
I attempted a
gridOptions.api.removeItems(selectedNode);
to clear the current and then
gridOptions.api.insertItemsAtIndex(2, savedNode);
but the drop event appeared to re-fire preventing that approach. Plus the insertItems (when ran first) falls over in internal ag-grid looping.
I would rather not re-sort the gridRows manually and then reset the gridRow data which would be somewhat clunky. This seems a common request on most grids so i assume it can be done but have just missed the relevant documentation. Thanks for any help..
K have finally got an Angular 2 method working, though currently I have to switch off sorting and filtering on the grid.
This particular example is relying on row selection being enabled (due to how it is finding some records). Grid dragdrop should be disabled (as that drags the grid visually which sucks) Instead use a processRowPostCreate to set up draggable params at the row level. This sets the dragged option to the row which looks much nicer.
in gridOptions
processRowPostCreate: (params) => {
this.generateRowEvents(params);
},
which calls
private generateRowEvents(params) {
params.eRow.draggable = true;
params.eRow.ondragstart = this.onDrag(event);
params.eRow.ondragover = this.onDragOver(event);
params.eRow.ondrop = this.onDrop(event);
}
I track the source recrord in the onDrag method
var targetRowId: any = $event.target.attributes.row.value;
this.savedDragSourceData = targetRowId;
onDragOver as usual
On drop we have to protect against an infinite loop (ag-grid appears to recall live methods when items are added to the grid hence the ondrop occurs multiple times) and then insert, delete and splice over both the grid and its data source ( I will carry on looking at using the grid to populate the data as opposed to the source data as that would allow source/filter, currently doign that inserts blank rows). An event (in this case) is then emitted to ask the owning component to 'save' the adjusted data.
private onDrop($event) {
if ($event && !this.infiniteLoopCheck) {
if ($event.dataTransfer) {
if (this.enableInternalDragDrop) {
this.infiniteLoopCheck= true;
var draggedRows: any = this.gridRows[this.savedDragSourceData];
// get the destination row
var targetRowId: any = $event.target.offsetParent.attributes.row.value;
// remove from the current location
this.gridOptions.api.removeItems(this.gridOptions.api.getSelectedNodes());
// remove from source Data
this.gridRows.splice(this.savedDragSourceData, 1);
if (draggedRows) {
// insert into specified drop location
this.gridOptions.api.insertItemsAtIndex(targetRowId, [draggedRows]);
// re-add rows to source data..
this.gridRows.splice(targetRowId, 0, checkAdd);
this.saveRequestEvent.emit(this.gridRows);// shout out that a save is needed }
this.v= false;
}
else {
this.onDropEvent.emit($event);
}
}
}
}
NOTE we are wrapping the grid in our own class to allow us to write one set of grid methods and not replicate over the application whenever the grid is used.
I will be refining this over the next few days but as a basic this allows the ag-grid in angular 2 to drag drop rows to sort records.
If you don't find a solution within ag-grid then you can do this by adding one more directive("ngDraggable") and integrate it with ag-grid.
Please find the following working plnkr for this.
https://embed.plnkr.co/qLy0EX/
ngDraggable
Hope this helps..

Add row to start of Dgrid instead of end using Rest call

As you know, dgrid 0.4 now uses the dstore package instead of dojo's store. Using the Rest.js in dstore, I simply want to add a new row to the dgrid using a rest call. This works fine. However, it adds the row at the end (as the last row) of the dgrid. I need to add the row at the beginning (making the newly added row the first row of the dgrid). Inside Rest.js, there is a variable called defaultNewToStart which I figured would do the trick, but even when set to true, dgrid still adds the row at the end. Any advice on how to get Rest.js in dstore to add a row to the beginning of the dgrid.
I figured out what I did wrong. In dgrid/OnDemandGrid, I set the property "sort", which was causing the queryExecutor in Trackable.js to put the newly added row at the end instead of the beginning. So all I had to do was remove the sort property, and now it works fine.
The add function of dstore/Memory supports PutDirectives as second argument other than the item you are trying to insert. PutDirectives has a property beforeId which can be used to insert the item before any existing record in store.
To add an empty row at the beginning:
var beforeID = null;
store.fetch().forEach(lang.hitch(this, function(data) { beforeId = data.id;}));
store.add({id: ''}, {beforeId: beforeID});

GXT 3 spinnerField validation

I want to validate that user cannot change spinner value manually by typing in text box of spinner.
For example a field sales multiple = x which I fetched from server not fix.
and displays a spinner field with limitation of like bellow
spinner.setMinValue = x
spinner.setIncrement = x
spinner.setValue = x
so user forcefully select a value which is multiple with x. e.g. if x=3 the user have to enter 3,6,9... and so on.
So here my issue is if I type a 2 in spinner field text box. GXT widget accept that value.
Posible solutions:
Is there any predefined properties of spinnerfield that i forget to set it?
Is there any predefined validator for this?
Can I set text box of spinner field read only by css so user cannot focus on text box but still change a value.
If none of above how to achieve manually?
i've searched a bit in the different classes and I don't see either a precise method which would set what you want.
Don't know about one, and even with one, a validator doesn't change the value in the input field, but maybe it's enough for your needs.
You can disable the text input by calling setEditable(boolean) on the spinnerfield (testSpinner.setEditable(false);)
Maybe you could search around the IntegerPropertyEditor, I haven't tried but as long as a new Spinner is like this:
SpinnerField<Integer> testSpinner = new SpinnerField<Integer>(new NumberPropertyEditor.IntegerPropertyEditor());
you can seen that there is another Constructor for IntegerPropertyEditor, which takes a "NumberFormat" param, but there is no NumberFormart() constructor, so I'm not sure about how you create your own one, but that could be an idea (to format numbers in the input to be a multiple of the increment).
The last option would be that Sencha forgot this possibility and that you should report this as a "bug" on the forum ?
Hope to have helped a bit, good luck :).

GWT 2.4 DataGrid automatic scrolling when selecting an item

I am using GWT 2.4's new DataGrid in a project. I configured the DataGrid with a pagesize of 50.
The available screen is not big enough to display all items and thus a vertical scrollbar is shown (this is actually the main purpose for using a DataGrid in the first place).
I attached a SingleSelectionModel to the DataGrid in order to be able to select items.
This works fine so far.
However I also have another widget with which the user can interact. Based on that user action a item from the DataGrid should be selected.
Sometimes the selected item is not in the visible screen region and the user has to scroll down in the DataGrid to see it.
Is there any way to automatically or manually scroll down, so that the selected item is visible?
I checked the JavaDocs of the DataGrid and found no appropriate method or function for doing that.
Don't know if this works, but you could try to get the row element for the selection and use the scrollIntoView Method.
Example Code:
dataGrid.getRowElement(INDEX_OF_SELECTED_ITEM).scrollIntoView();
The answer above works pretty well, though if the grid is wider than your window and has a horizontal scroll bar, it also scrolls all the way to the right which is pretty annoying. I was able to get it to scroll down and stay scrolled left by getting the first cell in the selected row and then having it scroll that into view.
dataGrid.getRowElement(dataGrid.getVisibleItems().indexOf(object)).getCells().getItem(0).scrollIntoView();
Don't have time to try it out, but DataGrid implements the interface HasRows, and HasRows has, among other things, a method called setVisibleRange. You just need to figure out the row number of the item that you want to focus on, and then set the visible range from that number n to n+50. That way the DataGrid will reset to put that item at the top (or near the top if it is in the last 50 elements of the list backing the DataGrid). Don't forget to redraw your DataGrid.
Have you already looked at this? If so, I'd be surprised that it didn't work.
Oh, and since this is one widget talking to another, you probably have some messaging set up and some message handlers so that when the user interacts with that second widget and "selects" the item, the message fires on the EventBus and a handler for that message fixes up the DataGrid along the lines I've described. I think you'll have to do this wiring yourself.
My solution, a little better:
dataGrid.getRow(model).scrollIntoView();
I got a Out of bounds exception doing the above.
I solved it getting the ScrollPanel in the DataGrid and used .scrollToTop() and so on on the ScrollPanel. However, to access the ScrollPanel in the DataGrid I had to use this comment:
http://code.google.com/p/google-web-toolkit/issues/detail?id=6865
As Kem pointed out, it's annoying the "scrollToRight" effect after the scrollIntoView. After me, Kem's solution gives a better behaviour than the base one as usually the first columns in a table are the more meaningful.
I improved a bit his approach, which scrolls horizontally to the first column of the row we want to be visible, by calculating the first visible column on the left before applying the scroll and then scrolling to it.
A final note: Columns absolute left is tested against "51". This is a value I found "experimentally" by looking the JS values in the browser's developer tool, I think it depends on the table's style, you may need to change/calculate it.
Below the code:
public void scrollIntoView(T next) {
int index = datagrid.getVisibleItems().indexOf(next);
NodeList<TableCellElement> cells = datagrid.getRowElement(index).getCells();
int firstVisibleIndex = -1;
for(int i=0; i<cells.getLength() && firstVisibleIndex<0;i++)
if(UIObject.isVisible(cells.getItem(i)) && (cells.getItem(i).getAbsoluteLeft() > 51) && (cells.getItem(i).getAbsoluteTop() > 0))
firstVisibleIndex = i;
cells.getItem(firstVisibleIndex>=0? firstVisibleIndex : 0).scrollIntoView();
}