Skip to content

How to set Focus on Grid Cell?

New Discussion
Martyn
Martyn asked on Nov 12, 2008 7:30 AM

I have a grid which is two banded, InvestmentCategory has one or more InvestmentGroups. I enter InvestmentGroups under one InvestmentCategory. I want to detect the Duplicate investmentGroup under one investmentCategory and if duplicate is detected, I want to setfocus on that cell. I have written JavaScript in AfterCellUpdateHandler, clientside event handler. But this is not working. Duplicate detection works fine but setFocus does not work.  SelectionType of Column is defined as single.

Here is how the code looks like,

function investmentCategoryUltraWebGrid_AfterCellUpdateHandler(gridName, cellId){

//Add code to handle your event here.

 

 

var col=igtbl_getColumnById(cellId);

if(col.Key!=‘description’)

return;var cell=igtbl_getCellById(cellId);

 

var Data=cell.getValue();

 

var row=cell.Row;

var index=row.getIndex();

//Finding Parent Row.

var parentRow=row.ParentRow;

 

//Now Finding Child RowCount of this Parent

 

 

var childRowCount=parentRow.ChildRowsCount;

 

for(var i=0;i<=childRowCount;i++)

{

if(index!=i) //Skip the one selected

 

{

var processingRow= parentRow.getChildRow(i);

var processingCellObj=processingRow.getCell(1);

var processingCellValue=processingCellObj.getValue();if(processingCellValue==Data)

{

alert(‘Duplicate detected, Please check your data’);

cell.setSelected(); //THIS PART OF THE CODE DOES NOT WORK,

cell.activate();

break;

}

}

}

}

Thank you very much for your help.

 

 

Sign In to post a reply

Replies

  • 0
    [Infragistics] Tony Lombardo
    [Infragistics] Tony Lombardo answered on Jul 25, 2008 7:41 PM

    It would be helpful to know what exactly isn't working.  Is the cell not being selected, or is focus not transferring?  Or is there a Javascript error being thrown?  My first guess is that the alert is interfering with what you're trying to do.  The problem with an alert box is that it's modal, and transfers focus away from what you're doing.  So even though you're trying to set focus to the cell, the Alert window is stealing the focus.  Try doing the same thing with out the alert, and see if that works better for you.  If so, I'd recommend using the Infragistics WebDialogWindow, since it is much more controllable than the standard alert box.  You can use the DialogWindow's closed event to then 'activate' the appropriate cell in the grid.

    Hope this helps,

    -Tony

    • 0
      Martyn
      Martyn answered on Jul 25, 2008 8:51 PM

      I tried to remove alert but still no luck. Actually the problem is, focus not transferring to the cell where duplicate is detected.

      Lets say, I have  Data

      01 – Row-1

      02- Row-2

      03- Row-3

      02- Row-4

      Newly added Row

      When i tab at Row-4 it creates new Row and Since 02 is duplicate because we already have it a Row-2, now I want the focus to be at 02 in Row-4 and selected. 

       

       

      • 0
        [Infragistics] Tony Lombardo
        [Infragistics] Tony Lombardo answered on Jul 29, 2008 2:50 PM

        You should execute your code on the BeforeEndEdit event rather than the UpdateCell event, and rather than setting the selected/active cell you should cancel the event – preventing the user from actually leaving the cell.

        You’ll want to return true from the method to cancel the event.  Here’s some pseudo-code

        function Grid_BeforeExitEditMode(gridName, cellID)
        {
        var cell=igtbl_getCellByID(cellID);
        if( cellValueIsDuplicate) return true;
        }

      • 0
        Chaitanya
        Chaitanya answered on Nov 12, 2008 7:30 AM

        Hello,

        Please use the following code, I had the same issue But the following code works for me,

        Example to check the entered cell value is a whole number 

        var curCell = igtbl_getCellById(itemName);

        var curCellValue = curCell.Element.innerText;if (isNaN(curCellValue) || curCellValue.indexOf('.') != -1)

        {

        alert('('+curCellValue +') is not a whole number, Please enter a whole number');

        curCell.setValue(prevCellValue,

        false); // Hold the previous value from the before enter edit mode handlercurCell.setSelected(true);
        curCell.activate();
        curCell.beginEdit();
        return false;

        }

        Regrads,
        Chaitanya…

         

         

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Martyn
Favorites
0
Replies
4
Created On
Nov 12, 2008
Last Post
17 years, 10 months ago

Suggested Discussions

Created by

Created on

Nov 12, 2008 7:30 AM

Last activity on

Feb 24, 2026 9:41 PM