Programatically create a block selection

In the dhtmlx grid version 1.6 build 80319.
I would like to programatically create a block selection (in javascript code).
I tried the code given in this other question, but it doesn’t work. … 439&a=6354

I’m using the following code and my grid doesn’t show anymore.

// Grid initialisation
var mygrid = new dhtmlXGridObject();
  // Disable selection of first column
  if ( mygrid._selectionArea.LeftTopCol <= 0 || mygrid._selectionArea.RightBottomCol <= 0) {
    return false;
  // This sends the selection to the server.
    mygrid._selectionArea.LeftTopCol - 1,
    mygrid._selectionArea.RightBottomCol - 1 );
  return true;

//the “refreshGrid” function is called when the grid changes. Sometimes new columns are added and the selection doesn’t get redrawn.
function refreshGrid()

            mygrid._selectionArea = mygrid._RedrawSelectionPos(
                mygrid.cellByIndex(#{selectedRegion.rightBottomRow}, #{selectedRegion.rightBottomCol})).cell;

Thank you,

Code which you are using is not exactly the same as was suggested.
Please check attached sample (92.9 KB)

It works!
Thank you,
I didn’t put the code inside a function as a parameter to loadXML.


The data loading is async, so data related commands need to be loaded only after XML loading, which can be catched by using second parameter of loadXML command

Would it be possible to do this selection from the xml file as an parameter?


You can call any method of grid from afterInit section , so it technically possible to call your custom code from afterInit, but it will not work for selection creation , because afterInit section processed when hea section parsed, but data not loaded in grid yet. There is no row in grid - so selection can’t be created.