AnyChart 7.12.0 Событие движущейся строки Ганта не включает индекс

Я попытался использовать пример перемещения, приведенный здесь, и e.itemIndex не определен. Мое первоначальное исследование объекта e не смогло найти атрибут индекса элемента. Я хотел бы знать старый индекс перемещаемого элемента и новый индекс элемента.

var tree = anychart.data.tree(getData(), anychart.enums.TreeFillingMethod.AS_TABLE);
    tree.listen(anychart.enums.EventType.TREE_ITEM_MOVE, function(e){
        chart.title.text("The "+e.itemIndex+" item was moved");
    });

См. мою скрипку здесь: http://jsfiddle.net/ax2t5hvt/


person AppMan    schedule 13.12.2016    source источник


Ответы (1)


Необходима некоторая хитрость, сохраните индекс:

  chart.listen(anychart.enums.EventType.ROW_MOUSE_DOWN, function(e) {
    var treeDataItem = e.item;
    absoluteSourceIndex = treeDataItem.meta('index');
  });

и тогда вы идете так:

  treeData.listen(anychart.enums.EventType.TREE_ITEM_MOVE, function(e) {
    /*
        Event e contains the following useful fields:
      e.type - Event type
      e.item - Moved item.
      e.target - Target data item that becomes a parent of the moved item.
        If is null, the parent is tree itself and moved item becomes root.
      e.targetIndex - Index of moved item in target item 
        (or in roots of tree if e.target is null)  
      e.source - Source data item, where the item moved from.
      e.sourceIndex - Old index of the moved item of the previous parent.
    */

    var treeDataItem = e.item;
    alert('Old absolute index: ' + absoluteSourceIndex + '\n' +
        'New absolute index: ' + treeDataItem.meta('index') + '\n' +
        'Old index in old parent tree data item: ' + e.sourceIndex + '\n' +
        'New index in new parent tree data item: ' + e.targetIndex);
  });

Вот рабочий пример: https://jsfiddle.net/mhm7hbsb/1/

person AnyChart Support    schedule 14.12.2016