New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Questions: How get select rows or columns index? #44
Comments
To select rows or columns index use
The callback method described in Demo Page- Save |
Thank you for @azizasm ! I understand you are saying. |
This is how I've done it: var selection = $("#exampleGrid").handsontable('getSelection'); selection is from col1,row1 to col2, row2 where col1 = selection.start().col; col2 = selection.end().col; Hope that helps |
thanks @bruceh48 ! I tryed it but it occurred javaScript Error. Perhaps you could go into a little more detail. |
Oops my mistake.. I had forgotten that I had added an additional function to the handsontable.js file. Its, I added it on line 2079, just after the function that starts with a line line that says : Without this, I could not "reliably" get the selection. Its works well for me. Hope that helps |
If you don't want to mess with the source code, all you really need is a little jQuery handler: var rowIndex; You could modify this just a bit to capture a row select from one of the arrow keys as well. |
Hi guys, I have created a callback called
Do you think @bruceh48 method still would be handy? I am thinking about including it in the core |
thanks @warpech ! |
Yes, bruceh48's method would be very useful. |
The code added by @bruceh48 has unpredictable behaviour depending on which direction the user makes his selection. For example: if the user makes a selection from a,b to c,d, he gets the coordinates (a,b), (c,d). However, if the user selects from b,c to a,d (the exact same area), he gets different coordinates. The following code fixes this error and is intended to replace the code given by @bruceh48 this.getSelected = function() {
var x1 = selection.start().row;
var y1 = selection.start().col;
var x2 = selection.end().row;
var y2 = selection.end().col;
if( (x1 <= x2 && y1 < y2) || (x1 < x2 && y1 <= y2) || (x1 == x2 && y1 == y2)) {
return [x1,y1,x2,y2];
}
else if( (x1 >= x2 && y1 > y2) || (x1 > x2 && y1 >= y2)) {
return [x2,y2,x1,y1];
}
else if(x1 < x2 && y1 > y2) {
return [x1,y2,x2,y1];
}
else if(x1 > x2 && y1 < y2) {
return [x2,y1,x1,y2];
}
}; The function $("#exampleGrid").handsontable('getSelected') now returns an array containing the coordinates, regardless of the direction of selection. [row1,col1,row2,col2] I have have created a fork with this code in the appropriate place. See https://github.com/littley/jquery-handsontable |
The method |
I would like to ask you the following questions;
How get select rows or columns index?
Do you have callback method return select rows or columns array index?
The text was updated successfully, but these errors were encountered: