Extjs4, Select grid row after reload grid - grid

I want to select a specific row after reload my grid.
and the specific row will be different in every process. So after reload grid, I want to select the row at the once. It does not effect to select the row later.
I tried like this,
//i is row index No. and i value is vary.
this.getMyGrid().fireEvent('itemclick',this.getMyGrid().getView(),this.getMyGrid().store.getAt(i)); // this reload grid
this.getMyGrid().getSelectionModel().select(i);// select row
but the code problem is select row before complete load grid.
How can I run the select code after grid load complete?
Thank you.

The grid's selection model has a method getLastSelected, you can can use something like this in the grid store's load event handler:
var myGrid = this.getMyGrid(),
selModel = myGrid.getSelectionModel();
selModel.select(selModel.getLastSelected());

Related

Insert a row between two existing rows in a dynamically created column in asp.net

I am creating a table dynamically.
Now I add some data to the table from Database.
On Every Row of the table I create a button.
Up to this it works fine.
Now when user clicks on that button I want to add a new row to the table just below the button was clicked. I mean I want to insert a new row between the existing rows.
Any Ideas?
If you are using a grid view or data table then apply the commandname property to the button then handle it in the grid view/data table command click method. From there you can determine which row the button is in and then create a new row and insert it below.
If you are creating the table HTML dynamically then it is a bit trickier, I would add HTML comments after each row with the row number and give each button a command argument with the row number too so I could replace the comment text with a new row.
tbl.rows.addAt(Position)
Here Positoion is the variable holding the value where to insert the new row.
when use this code you can insert row between other rows in datatable in vb.net
tbl.Rows.InsertAt(newRow, CurrentRow)

Maintaining Row Selection in ASP.NET GridView Control

The Setup:
I currently have a page with a GridView control on it inside of an update panel, using a SqlDataSource. I have a timer setup to update the GridView every X amount of seconds. Typically for what I am testing every time the GridView updates about 4-5 new rows of data are added to the gridview, while the last 4-5 get tossed out. I am only displaying 15 results at a time and will have new results coming in every update.
The Problem:
I allow the user to select the rows, while the GridView is being updated. I am handling this by setting the SelectedIndex property. However, when I select a row and then the grid is updated the row the user selected gets pushed down about 4-5 rows and the data in the previous selected index is selected instead. So where they clicked is selected at this point, not what they clicked.
I need a way to determine, if possible from the SqlDataSource/Gridview, how many new rows have been added to the gridview. OR a way to maintain the selected data by the data in the row and not just the SelectedIndex.
Any help is appreciated, thanks.
RESOLVED:
Ok I went ahead and added a new invisible column to my grid, and am now keep track of the unique ID's selected from the DB. By setting an array before databinding, and comparing that to the new array I get after databinding I was able to use a simple Intersect to determine the number of rows that are the same. Then I used that to determine from the total how many are new this postback.
Just an idea:
I think you can use an invisible column (more specifically an ID column) to store the selected rows' IDs value in the Session object and then after the grid updates, you can retrieve this value(s) and select the row(s) again if they are still present.
If you have custom GridView OnRowUpdating event.
public void GridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
Session["CurrIndex"] = GridView.SelectedIndex;//index before insertion
Session["RowCount"] = GridView.Rows.Count;//row count before insertion
//Add new Rows
GridView.SelectedIndex = (Int32)(Session["CurrIndex"]) + ( GridView.Rows.Count - (Int32)(Session["RowCount"]);//update selected index
Session["CurrIndex"] = GridView.SelectedIndex;//restore the index into session
}

Flex Datagrid insert row below current row

my application needs to allow users to insert rows below the current datagrid row. My solution is to to add a row to the dataproviders collection. This works, but the row does not appear beneath the current row the user clicked on.
The Datagrid has a default sort order (date ASC), which re-orders the data...so this seems to affect the position of the row in the grid.
Any ideas how to fix this?
Two possible answers:
1. define your own sort function that sorts according to item order in dataprovider (i.e. it does nothing), and assign it to the sortFunction property
2. simply comment out the sorting of the data inside the component.

Calculate total by javascript in gridview with paging

Without paging function, i can loop through the gridview by using
var sum = 0;
var gridViewCtlId = '<%=timesheetView.ClientID%>';
var grid = document.getElementById(gridViewCtlId);
var gridLength = grid.rows.length;
so with gridLength i can loop through the gridview to sum all rows. However, when I use paging event of gridview, i use the page size to loop through all rows, but it occurs errors because the last page may not have enough rows. So would you please to help me how to get the rows in the each page of gridview?
What you have is correct, just update the gridLength property just before calculating the sum. There's no way for javascript to know the number of rows until the grid is there and present on the page...but that's what you're doing already, so just update that row count.
The only way I picture what you currently have not working is you have this code running initially and not when an UpdatePanel (or other loading mechanism) comes back, just re-grabbing the gridLength will resolve this, as the updated <table> in the DOM will have the correct number of rows.
In your loop, you can do a check like this
if (grid.rows[rowIndex]){
// Your code to calculate sum goes here
}

How to get proper row index values of grid view after sorting

I have an asp.net application in which I am using a grid view. Paging and sorting are applied to the grid view. One action what I am doing is on click of any grid view row, am getting the column values of the selected row and redirecting to the other page.
The problem is after the grid view is sorted, if I click on any of the row in ayy page (paging index), am getting only first page values even though the visible row is different.
I am getting the row values in gridview_rowcreated() method and putting in some variable. In sorting scenario, before sorting is done, the gridview_rowcreated() method is called but not after the sorting is done.
In case you still need an answer to this...
You should be using the gridview's SelectedIndexChanging event with something like the following:
gridView.Rows.Item(intNewIndex).Cells(# of column, zero-based).Text
This will give each cell's current value, you'll just have to loop through each cell and assign each cell's value to desired variable(s).
Hope this helps!!!

Resources