Jump to content

Skip to the next line in a unidbgrid...


milton luiz

Recommended Posts

I wanted this method as it was made to jump from the line in line and jump from column to column and when it reached the last column jumped to the next line, understood?

 

function reconfigure(sender, store, columns, oldStore, the, eOpts) {
    var grid = sender;
    for (var i = 0; i < columns.length; i++) {
        if (columns.getEditor()) {
            columns.getEditor().on('specialkey', function(field, e) {
                if (e.getKey() == 13) {
                    var store = grid.getStore();
                    var selModel = grid.getSelectionModel();
                    var selectedRecord = selModel.getLastSelected();
                    var recordIndex = store.indexOf(selectedRecord);
                    var nextRecord = store.getAt(recordIndex + 1);
                    
if (nextRecord) {
                        selModel.select(nextRecord);
                        if (grid.editingPlugin && grid.uniRow && grid.uniCol){
                          var _row = grid.uniRow;
                          var _col = grid.uniCol;
                          setTimeout(function(){
                            grid.editingPlugin.startEdit(_row, _col);
                          }, 10);
                        }
                    }
                }
            })
        }
    }
}
Link to comment
Share on other sites

This is similar to the other when it goes to the next field it is already in the editing state. Do a test on a grid with no record and try to include a new record using this function you showed, see that when it arrives in the last column it does nothing, neither the tab nor the enter work...

Link to comment
Share on other sites

Hi Eduardo,

 

 

 

Thank you!

 

Yes, it can be done,By the way, you can make a test case, and give us a download linkWe will try to analyze it and find a solution.

 

Best regards,

Ok I will try...

Link to comment
Share on other sites

Hi,

 

Can you try this ?!

If this is normal for you, we will optimize the code:

function reconfigure(sender, store, columns, oldStore, oldColumns, eOpts) 
{
    var grid = sender;
    for (var i = 0; i < columns.length; i++) {
        if (columns[i].getEditor()) {
            columns[i].getEditor().on('specialkey', function(field, e) {
                if (e.getKey() == 13) {
                    var store = grid.getStore();
                    var selModel = grid.getSelectionModel();
                    var selectedRecord = selModel.getLastSelected();
                    var recordIndex = store.indexOf(selectedRecord);

                    if (columns[grid.uniCol].isLastVisible) {
                        var nextRecord = store.getAt(recordIndex + 1);
                        if (nextRecord) {
                            selModel.select(nextRecord);
                        };
                    };

                    if (grid.editingPlugin && grid.uniRow && grid.uniCol) {
                        var _row = grid.uniRow;
                        var _col;

                        if (!columns[grid.uniCol].isLastVisible) {
                            _col = grid.uniCol + 1
                        } else {
                            _col = 1; // first editable column index
                        };

                        setTimeout(function() {
                            grid.editingPlugin.startEdit(_row, _col);
                        }, 10);
                    };

                }
            })
        }
    }
}

Best regards,

Link to comment
Share on other sites

If I am editing the first line of the grid it does nothing, I give enter but nothing happens. If it's the second line it edits and jumps to the next field. When I am in the last field and press enter it jumps down the line being that it is in the last column, it should go to the first column.

Link to comment
Share on other sites

Hi,

 

Can you try this approach ?!:

function reconfigure(sender, store, columns, oldStore, oldColumns, eOpts)
{
    var grid = sender;
    function fn() {
        var selModel = grid.getSelectionModel();
        var _row = selModel.getCurrentPosition().row;
        var _col = selModel.getCurrentPosition().column;

        if (grid.columnManager.columns[_col].isLastVisible) {
            _col = 0;
            _row += 1;
        } else {
            _col += 1;
        };

        setTimeout(function() {
            grid.getSelectionModel().select({
                row: _row,
                column: _col
            });
            grid.editingPlugin.startEdit(_row, _col);
        }, 10);
    };

    for (var i = 0; i < columns.length; i++) {
        var hasEditor = columns[i].getEditor();
        var ed = hasEditor || columns[i];

        if (columns[i].checkColumn) {
            columns[i].on('keydown', function(a, b, c, d, e) {
                if (e.getKey() == 13) {
                    fn();
                }
            })
        } else if (columns[i].rdonly) {
            ed.on('keydown', function(a, b, c, d, e) {
                if (e.getKey() == 13) {
                    fn()
                }
            })
        } else {
            ed.on('specialkey', function(field, e) {
                if (e.getKey() == 13) {
                    fn();
                }
            })
        }
    }
}

Best regards,

Link to comment
Share on other sites

Hi,

 

Can you try this approach ?!:

function reconfigure(sender, store, columns, oldStore, oldColumns, eOpts)
{
    var grid = sender;
    function fn() {
        var selModel = grid.getSelectionModel();
        var _row = selModel.getCurrentPosition().row;
        var _col = selModel.getCurrentPosition().column;

        if (grid.columnManager.columns[_col].isLastVisible) {
            _col = 0;
            _row += 1;
        } else {
            _col += 1;
        };

        setTimeout(function() {
            grid.getSelectionModel().select({
                row: _row,
                column: _col
            });
            grid.editingPlugin.startEdit(_row, _col);
        }, 10);
    };

    for (var i = 0; i < columns.length; i++) {
        var hasEditor = columns[i].getEditor();
        var ed = hasEditor || columns[i];

        if (columns[i].checkColumn) {
            columns[i].on('keydown', function(a, b, c, d, e) {
                if (e.getKey() == 13) {
                    fn();
                }
            })
        } else if (columns[i].rdonly) {
            ed.on('keydown', function(a, b, c, d, e) {
                if (e.getKey() == 13) {
                    fn()
                }
            })
        } else {
            ed.on('specialkey', function(field, e) {
                if (e.getKey() == 13) {
                    fn();
                }
            })
        }
    }
}

Best regards,

 

It worked perfect, congratulations for the great work of you, that's why I bought the tool, besides being great, also has a great support. Thank you!!

Link to comment
Share on other sites

I'm sending another example so you can see what happens. When you edit the Address column onwards, it says exactly what you did, but when it arrives in the Cep column and gives an Enter, even without making any changes to the registry, the system cancels the changes that were made in the previous columns. Another problem I noticed was when I am in the last line and in the last field and I click on enter and the system does not execute any view of ClientDataSet. When I'm in the last column I give the enter in the ClientDataSet in the AfterPost event I give an ApplyUpdates (0).

Grid - DbGrid Editavel.rar

Link to comment
Share on other sites

Hi,

 

I'm sending another example so you can see what happens. When you edit the Address column onwards, it says exactly what you did, but when it arrives in the Cep column and gives an Enter, even without making any changes to the registry, the system cancels the changes that were made in the previous columns.

 

Yes, because your value in "Cep column" is incorrect.

 

You can try to use this approach for this issue:

function canceledit(editor, context, eOpts)
{
    if (context.originalValue === context.value) {
        return false
    };
}

Best regards,

Link to comment
Share on other sites

  • 4 months later...

How to use this function in Grid with GroupHeader? Show error:

columns.getEditor is not a function
 
 

function reconfigure(sender, store, columns, oldStore, oldColumns, eOpts)

{

 

    var grid = sender;

 

    for (var i = 0; i < columns.length; i++) {

 

        if (columns.getEditor()) {

            columns.getEditor().on('specialkey', function(field, e) {

 

                if (e.getKey() == 13) {

 

                    var store = grid.getStore();

 

                    var selModel = grid.getSelectionModel();

 

                    var selectedRecord = selModel.getLastSelected();

 

                    var recordIndex = store.indexOf(selectedRecord);

 

                    var nextRecord = store.getAt(recordIndex + 1);

 

                    if (nextRecord) {

 

                        selModel.select(nextRecord);

 

                        if (grid.editingPlugin && grid.uniRow && grid.uniCol){

 

                          var _row = grid.uniRow;

                          var _col = grid.uniCol;

                          setTimeout(function(){

 

                            grid.editingPlugin.startEdit(_row, _col);

 

                          }, 10);

 

                        }

 

                    }

 

                }

 

            })

 

        }

 

    }

 

}

How to use this function in Grid with GroupHeader? Show error

Link to comment
Share on other sites

  • 3 months later...

Hi,

 

Then try:

function reconfigure(sender, store, columns, oldStore, the, eOpts) {
    var grid = sender;
    for (var i = 0; i < columns.length; i++) {
        if (columns[i].getEditor()) {
            columns[i].getEditor().on('specialkey', function(field, e) {
                if (e.getKey() == 13) {
                    var store = grid.getStore();
                    var selModel = grid.getSelectionModel();
                    var selectedRecord = selModel.getLastSelected();
                    var recordIndex = store.indexOf(selectedRecord);
                    var nextRecord = store.getAt(recordIndex + 1);
                    if (nextRecord) {
                        selModel.select(nextRecord);
                    }
                }
            })
        }
    }
}

Best regards.

 

 

Where this javascript have to be put ?

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...