Git Product home page Git Product logo

Comments (12)

warpech avatar warpech commented on May 12, 2024 1

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

from handsontable.

azizasm avatar azizasm commented on May 12, 2024

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

from handsontable.

 avatar commented on May 12, 2024

Thank you for @azizasm !

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

from handsontable.

bruceh48 avatar bruceh48 commented on May 12, 2024

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

from handsontable.

 avatar commented on May 12, 2024

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.

from handsontable.

bruceh48 avatar bruceh48 commented on May 12, 2024

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

from handsontable.

 avatar commented on May 12, 2024

thanks @bruceh48 !

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

from handsontable.

bgl3317 avatar bgl3317 commented on May 12, 2024

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.

from handsontable.

warpech avatar warpech commented on May 12, 2024

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

from handsontable.

 avatar commented on May 12, 2024

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

from handsontable.

littley avatar littley commented on May 12, 2024

@warpech

Yes, bruceh48's method would be very useful.

from handsontable.

littley avatar littley commented on May 12, 2024

@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

from handsontable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.