Skip to content
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

Closed
ghost opened this issue Jun 30, 2012 · 12 comments
Closed

Questions: How get select rows or columns index? #44

ghost opened this issue Jun 30, 2012 · 12 comments

Comments

@ghost
Copy link

ghost commented Jun 30, 2012

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?

@azizasm
Copy link

azizasm commented Jul 2, 2012

To select rows or columns index use selectCell and specify the index. Example below to select the row/col 0,0

container.handsontable("selectCell", 0, 0);

The callback method described in Demo Page- Save

@ghost
Copy link
Author

ghost commented Jul 2, 2012

Thank you for @azizasm !

I understand you are saying.
But I would like to know column and row index selecting now.

@bruceh48
Copy link

bruceh48 commented Jul 4, 2012

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;
row1 = selection.start().row;

col2 = selection.end().col;
row2 = selection.end().row;

Hope that helps

@ghost
Copy link
Author

ghost commented Jul 5, 2012

thanks @bruceh48 !

I tryed it but it occurred javaScript Error.
The details of Error: $(this).data("handsontable")[action] is undefined

Perhaps you could go into a little more detail.

@bruceh48
Copy link

bruceh48 commented Jul 5, 2012

Oops my mistake..

I had forgotten that I had added an additional function to the handsontable.js file.

Its,
/**
* Returns the selection
*/
this.getSelection = function()
{
return selection;
};

I added it on line 2079, just after the function that starts with a line line that says :
this.selectCell = function

Without this, I could not "reliably" get the selection.

Its works well for me.

Hope that helps

@ghost
Copy link
Author

ghost commented Jul 6, 2012

thanks @bruceh48 !

Mr. @warpech !
I'm glad you add above-mentioned @bruceh48 's code!
I beg your kindness.

@bgl3317
Copy link

bgl3317 commented Jul 6, 2012

If you don't want to mess with the source code, all you really need is a little jQuery handler:

var rowIndex;
$('#yourTable tr').click(function () { rowIndex = $(this).index() });

You could modify this just a bit to capture a row select from one of the arrow keys as well.

@warpech
Copy link
Member

warpech commented Jul 11, 2012

Hi guys, I have created a callback called onSelection. Use it as shown in http://warpech.github.com/jquery-handsontable/demo/conditional.html:

container.handsontable({
  ...

  onSelection: function(row, col, row2, col2) {
    var meta = container.handsontable('getCellMeta', row2, col2);
    if(meta.isWritable == false) {
      container.handsontable('updateSettings', {fillHandle: false});
    }
    else {
      container.handsontable('updateSettings', {fillHandle: true});
    }
  },

  ...
}

Do you think @bruceh48 method still would be handy? I am thinking about including it in the core

@ghost
Copy link
Author

ghost commented Jul 12, 2012

thanks @warpech !
I've found what I want to do.

@ghost ghost closed this as completed Jul 12, 2012
@littley
Copy link
Contributor

littley commented Jul 23, 2012

@warpech

Yes, bruceh48's method would be very useful.

@littley
Copy link
Contributor

littley commented Jul 24, 2012

@warpech @bruceh48

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

@warpech
Copy link
Member

warpech commented Jul 28, 2012

The method getSelected is now included in core. Thanks guys!

budnix pushed a commit that referenced this issue Nov 27, 2018
… be centered (#52)

* Centered buttons which will have min-width #44

* Try to equalize margins #44

* One more CSS change

* One yet change
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants