【问题标题】:How to move handson table scroll bar to specific row and column..?如何将动手表滚动条移动到特定的行和列..?
【发布时间】:2014-09-19 14:32:10
【问题描述】:

我正在尝试找出一种方法或方式,通过它我可以将动手表滚动条移动到特定的行和列。 我尝试使用 selectCell (row: Number, col: Number, rows: Number, cols: Number, scrollToSelection: Boolean (Optional)) 但它似乎不起作用

这里是它的小提琴链接http://jsfiddle.net/hpfvc9bx/

$(document).ready(function () {

  function createBigData() {
    var rows = []
      , i
      , j;

    for (i = 0; i < 1000; i++) {
      var row = [];
      for (j = 0; j < 6; j++) {
        row.push(Handsontable.helper.spreadsheetColumnLabel(j) + (i + 1));
      }
      rows.push(row);
    }

    return rows;
  }

  var maxed = false
    , resizeTimeout
    , availableWidth
    , availableHeight
    , $window = $(window)
    , $example1 = $('#example1');

  var calculateSize = function () {
    if(maxed) {
      var offset = $example1.offset();
      availableWidth = $window.width() - offset.left + $window.scrollLeft();
      availableHeight = $window.height() - offset.top + $window.scrollTop();
      $example1.width(availableWidth).height(availableHeight);
    }
  };
  $window.on('resize', calculateSize);

  var table = $example1.handsontable({
    data: createBigData(),
    colWidths: [55, 80, 80, 80, 80, 80, 80], //can also be a number or a function
    rowHeaders: true,
    colHeaders: true,
    fixedColumnsLeft: 2,
    fixedRowsTop: 2,
    minSpareRows: 1,
    stretchH: 'all',
    contextMenu: true,
      afterChange : function(changes){
          console.log(changes);
      }  
  });

  $('.maximize').on('click', function () {
    maxed = !maxed;
    if(maxed) {
      calculateSize();
    }
    else {
      $example1.width(400).height(200);
    }
    $example1.handsontable('render');
  });

    $("#setSelectedRow").on('click',function(){

        console.log(table);
        table.select(9,3,12,6,true); // not working as it doesnt move scroll bar to specified column and range


    })

  function bindDumpButton() {
      $('body').on('click', 'button[name=dump]', function () {
        var dump = $(this).data('dump');
        var $container = $(dump);
        console.log('data of ' + dump, $container.handsontable('getData'));
      });
    }
  bindDumpButton();

});

谁能帮我解决这个问题...

提前谢谢...

【问题讨论】:

    标签: handsontable


    【解决方案1】:

    您可以使用handsontable 的"selectCell" 移动到特定单元格。

    您在$("#setSelectedRow").on('click',function(){.... 中使用了table.select(...) 当您使用表格 DOM 元素时,它不起作用,但您需要具有可动手操作的“实例”。可以这样做,

    第一种方式:

    var tblInstance = $example1.handsontable('getInstance');
    

    然后申请"selectCell()"

    tblInstance.selectCell(rowNum, colNum);
    

    第二种方式:

    使用$example1.handsontable("selectCell", rowNum, colNum);

    请参考fiddle for the second way,其中:

    $("#setSelectedRow").on('click',function(){        
        console.log(table);        
        $example1.handsontable("selectCell", 9, 5);  // select 9th row's 5th column
    
    })
    

    希望对你有帮助:)

    【讨论】:

    • @Swapnil Navalakha,你的答案还好吗?或者您需要任何进一步的解释?随时欢迎您的询问:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多