Extract row index from slickgrid using a unique cell value - slickgrid

rowname="r1";
changes[1]["num1"] = "changed";
grid.invalidateRow(1);
grid.setCellCssStyles("highlight", changes);
grid.render();
Is there a way to get the index of a row in slickgrid if I have a cell value of first column which is unique? In the above code I want to use as changes[rowindex]["num1"]="changed" where "num1" is my column name and "r1" is first column cell value.changes["r1"]["num1"]="changed" does not works.

Do it like this...
for(var i=0; i<grid.getDataLength(); i++){
if(grid.getData()[i].firstColumnID == 'firstColumnValue'){
rowIndex = i;
}
}

getRowById(id) - Returns the index of a row with a given id

I know I'm late but may be with better solution?
grid.getData().getIdxById('UniqueFieldValue')

Related

slickgrid - grid.getDataItem(0), dataView.getItem(0) and .dataView.getItemByIdx(0) returning reference

I'm trying to duplicate a row, but change like one column.
So I do something like this:
var item = myGrid.grid.getDataItem(rowIndex);
item.id=123;
myGrid.dataView.addItem(item);
My issue is that if I am duplicating the row at index 0, when I do:
item.id = 123;
It actually makes id of the row at index 0 as 123 as well as the new line.
Is there a way to get the data and not get the actual reference to the row?
Thanks!
In this case, I would use the jQuery $.extend method to create a new object:
var newItem = {};
$.extend(newItem, item);
newItem.id=123;
myGrid.dataView.addItem(newItem);

Get column number from column name

Is there any method to get the column number from the column name?
I can only retrieve the column name, and I need the column number for getCellMeta.
Thanks
Made this function that solved my problem:
function GetColFromName(name)
{
var n_cols = $editorTableContainer.handsontable('countCols');
var i = 1;
for (i=1; i<=n_cols; i++)
{
if (name.toLowerCase() == $editorTableContainer.handsontable('getColHeader', i).toLowerCase()) {
return i;
}
}
return -1; //return -1 if nothing can be found
}
This is almost what I required but not quite as I needed the column prop. I couldn't find the answer anywhere so thought I would add this to the thread that helped me.
instead of using 'getColHeader' use 'colToProp'.
Use propToCol("Column Name"). This returns the column's index.

How can I insert a row after the row that is now selected in a sorted table

this is more or less a duplicate of the ones below:
How can i sort java JTable with an empty Row and force the Empty row always be last?
http://www.java.net/node/645655
the only difference is that i would like to insert the new row after the row that is currently selected. the default behavior of DefaultRowSorter would sort immediately when the row is inserted, while what i need is to turn off sorting temporarily so that i could insert the row in a position that i specified, not a position from the sorter
i noticed that there were 2 links provided in How can i sort java JTable with an empty Row and force the Empty row always be last?, but they are not valid anymore, that's why i created this new question.
I copied completely DefaultRowSorter and TableRowSorter from JDK and changed insertInOrder() like below and it seems now working as I expected.
for (int i = 0; i < max; i++) {
if(sortOnInsert)
{
index = Arrays.binarySearch(current, toAdd.get(i));
if (index < 0) {
index = -1 - index;
}
}
else
{
Row rowBeforeAdd = new Row(this, toAdd.get(i).modelIndex - 1);
index = Arrays.binarySearch(current, rowBeforeAdd);
if (index < 0) {
index = viewToModel.length - 1;
}
else
{
index += 1;
}
}

Is there a way to get the column number by column name in jqgrid

I tried to access the rowObject in custom formatter function by column name but it didn't give any values. I have tried this with both JSON and XML data type .
Is there any way to get the column number by column name in jqgrid.
function Draw_Link ( cellvalue , options , rowObject )
{
return "<a href='someurl.php?col_name="+rowobject.col_name+"'>"+cellvalue+"</a>";
}
The column index for the column is the same as the index of the column in the colModel array before the jqGrid initialization (it is the same as in the input parameter colModel). If you use rownumbers:true, multiselect:true or subGrid:true additional columns will be addid to the grid as the first rows, so the column index which one has in the colModel array as the jqGrid parameter can be other as one have after the grid initialization. You can use for example this simple function to get the index
var getColumnSrcIndexByName = function(grid,columnName) {
var cm = grid.jqGrid('getGridParam','colModel'),
i=0, index=0, l=cm.length, cmName;
while (i<l) {
cmName = cm[i].name;
i++;
if (cmName===columnName) {
return index;
} else if (cmName!=='rn' && cmName!=='cb' && cmName!=='subgrid') {
index++;
}
}
return -1;
};
var index = getColumnSrcIndexByName($("#list"),'MyColumn');
UPDATED: Free jqGrid fork simplifies getting column index from column name because it holds internally the parameter iColByName, which is the map by the column name. One can just get iColByName via
var iColByName = $("#list").jqGrid("getGridParam", "iColByName");
and iColByName["MyColumn"] will be the required column index (iCol). I remind that one can use getGridParam without any parameter to get the reference to all parameters of jqGrid:
var p = $("#list").jqGrid("getGridParam");
The value
var iCol = p.iColByName["MyColumn"];
will be the column index and p.colModel[iCol].name will be "MyColumn".

How to iterate through table using selenium?

I have a table called UserManagement that contains information about the user.This table gets updated whenever new user is created. If i create two users then i need check whether two users are actually created or not. Table contains ID,UserName,FirstName,LastName,Bdate..ctc. Here ID will be generated automatically.
I am running Selenium-TestNG script.Using Selenium,how can i get the UserName of the two users which i have created? Should i have to iterate through table? If so how to iterate through the table?
Use ISelenium.GetTable(string) to get the contents of the table cells you want. For example,
selenium.GetTable("UserManagement.0.1");
will return the contents of the table's first row and second column. You could then assert that the correct username or usernames appear in the table.
Get the count of rows using Selenium.getxpathcount(\#id = fjsfj\td\tr") in a variable rowcount
Give the columncount in a variable
Ex:
int colcount = 5;
Give the req i.e New user
String user1 = "ABC"
for(i = 0;i <=rowcount;i++)
{
for(j=0;j<=colcount;j++)
{
if (user1==selenium.gettable("//#[id=dldl/tbody" +i "td"+j))
{
system.out.println(user1 + "Inserted");
break;
}
break;
}
}
Get the number of rows using:
int noOfRowsInTable = selenium.getXpathCount("//table[#id='TableId']//tr");
If the UserName you want to get is at fixed position, let's say at 2nd position, then for each row iterate as given below:
selenium.getText("xpath=//table[#id='TableId']//tr//td[1]");
Note: we can find the number of columns in that table using same procedure
int noOfColumnsInTable = selenium.getXpathCount("//table[#id='TableId']//tr//td");
Generically, something like this?
table = #browser.table(:id,'tableID')
table.rows.each do |row|
# perform row operations here
row.cells.each do |cell|
# do cell operations here
end
end

Resources