ExtJs / Sencha : how to highlight a grid row after insert? - grid

I want to create such a grid:
http://www.sencha.com/deploy/dev/examples/grid/edit-grid.html
Actually I already did, but I want to highlight the last inserted row of my grid (in extjs this is the function highlight(), which does a yellowfade on the element).
I didn't actually succeed in doing this... my problem is that I can't get the row I just inserted, and thus obviously I can't highlight it.
Any clues?
Thanks in advance

You only need to do this (here for row number one):
var row = grid.getView().getRow(0);
Ext.get(row).highlight();
It's that easy.

The code has
store.insert(0, p);
So don't you just highlight row zero immediately after that statement?

yes sorry for answering too late,
use Ext.grid.RowSelectionModel and than use selectLastRow function u can easily will be able to point it out :)

Ext.data.store has a add listener which is passed an index at which records were inserted
add : ( Store this, Ext.data.Record[] records, Number index )

This would go inside of your add/create button event. The code this.getSelectionModel().select(0); will highlight the first row since we inserted into position 0, we are selecting position 0. This code works with ExtJS 4.2.0.
var rec = Ext.create('App.model.GridModel', {
id: '123',
name: 'ABC'
});
this.store.insert(0, rec);
this.getSelectionModel().select(0);

Related

How to make a row in a grid not appear if it's value is 0?

I only have two fields in my grid. Just need the entire row to not appear, if the value in one of the fields is 0.
There are multiple solutions for your need, but this one is working for me in a similar setup.
Following code is in the PostBuild event of the component:
Local Rowset &rs;
&rs = GetLevel0()(1).GetRowset(Scroll.MainRecordOfTheGrid);
&rs.Flush();
&rs.Select(Record.MainRecordOfTheGrid, "WHERE FieldA<>0 and FieldB<>0");

Bootstrap table checking

I was trying to check a row inside a Bootstrap table using this function:
$('#editMappingTable').bootstrapTable('check', var);
var is dynamic variable(number) which will have the row id I want to check but its not working.
If I use this technique :
$('#editMappingTable').bootstrapTable('check', 1);
the above one works well .
What should I do?
Please make sure that you are passing a valid row index

How to detect doubleClick in QTableView

I'm using PyQt to create a GUI application. In a view inherited from QTableView, need to detect the row the user has selected when they double click a row. The table has sorting, but no editing.
How do I do it?
Note - tried the doubleClicked(int) signal. It is emitted by mouse buttons, not by data cells, so it was never fired. :(
Ian
I dont understand.
The doubleClicked signal of the QTableView has the signature
void doubleClicked ( const QModelIndex & index )
If you connect that signal you should obtain the correct QModelIndex.
No need to use SIGNALs anymore:
self.your_table.doubleClicked.connect(your_function)
"doubleClicked" being inherited from QAbstractItemView.
Once you have the modelIndex, (from Frank's comment above) you can use it to find which cell was double clicked.
def slotDoubleClicked(self, mi):
row = mi.row()
column = mi.column()
You then can use these row and col values to access the table with table.setItem(row, column, newdata) or other table method
Like #regomodo said, you can simply connect your function to the double click via:
self.your_table.doubleClicked.connect(your_function)
Then, if you want to know on which row the user double clicked, you can use the following code:
for idx in self.your_table.selectionModel().selectedIndexes():
row_number = idx.row()
column_number = idx.column()
It will return an integer corresponding to the row or the column number.
There will always only be a single value as the double click remove the previous selection.
If you link your function to a push button or another signal, you can receive a list containing multiple elements selected by the user.
For example, you can easily retrieve a list of all selected rows using this code:
rows = []
for idx in self.your_table.selectionModel().selectedIndexes():
rows.append(idx.row())
rows = list(set(rows))
This will return a list of all selected rows (The set function will also remove any duplicates).
Cheers!

How to get this QTableWidget to display items?

I have a QTableWidget and I can't get anything to show up in it.
The following appears in the constructor of the main window:
ui->tableWidget->setItem(0,0,new QTableWidgetItem("Item1"));
ui->tableWidget->setItem(0,1,new QTableWidgetItem("Item2"));
ui->tableWidget->setItem(0,2,new QTableWidgetItem("Item3"));
When I run the application, the table widget shows up, but the items do not.
I tried adding ui->tableWidget->insertRow(0); before the above code, but it didn't work.
Aha! I figured out what was going on... I needed to tell the control the number of rows it should have:
ui->tableWidget->setRowCount(2);
Example code:
//this will give the present number of rows available.
int insertRow = ui->tableWidget->rowCount();
//insert the row at the bottom of the table widget - using.
ui->tableWidget->insertRow(insertRow);
//After a new row is inserted we can add the table widget items as required.
ui->tableWidget->setItem(insertRow,0,new QTableWidgetItem("Item1"));
ui->tableWidget->setItem(insertRow,1,new QTableWidgetItem("Item2"));
ui->tableWidget->setItem(insertRow,2,new QTableWidgetItem("Item3"));

Change item sortorder in gridview - LINQToSQL

I've got a gridview with a list of categories. In the database (MSSQL2008), the category table has a SortOrder(INT) NULL field.
Currently categories are retrieved using:
Galleries.DataSource = From G In DB.GalleryCategories Order By G.SortOrder, G.Name
Now, what I need to be able to do is add "Move Up" and "Move Down" buttons to each row to allow the user to sort the items in an arbitrary way.
My initial thoughts are along the lines of:
Identify ID of selected item.
Identify ID of item before/after selected item.
Swap of identified items in the DB SortOrders.
I would then have make the sortorder NOT NULL and make sure it's initialised to a unique number
I'd appreciate any alternative suggestions / comments on this approach
Many thanks
I have generally seen it done this way, and have done it myself
SortOrder is an int
Each item increases by 10 (so, 10,20,30,40) or suitable increment
To move an item up, subtract 15
To move an item down, add 15
To insert an item, take the target and add/subtract 1
Apply a NormalizeSort() routine which resets the values to even intervals
10,20,25,30,40 => 10,20,30,40,50
That makes it all pretty simple, since inserting something above something else is just:
list.Add( New Item(..., target.SortOrder +1) )
list.NormalizeSort()
// or
item.SortOrder += 11, etc
If you want to make it a decimal, then you can just make it all sequential and just add .1, etc to the sort order and re-normalize again.
// Andrew
I believe
Galleries.AllowSorting = true;
would be far enough ;)

Resources