FlexGrid and merged cells

Posted by: qualton on 14 September 2017, 11:15 am EST

    • Post Options:
    • Link

    Posted 14 September 2017, 11:15 am EST

    The examples cover merging pretty well: http://demos.componentone.com/wijmo/5/Angular/Explorer/Explorer/#/grid/merging

    I do still have a couple questions:

    • 1 -

      Is merging of cells horizontally intentionally left out?

    From another post http://wijmo.com/reply/reply-to-multiple-rows-of-column-headers-grouped-column-headers-11/ I understand that without a custom MergeManager “The grid merges either rows or columns, but not both”.

    So if i set the grid allowMerging=“Cells” and then for every column that is created have allowMerging=false, I should have a grid that merges cells horizontally. This, however, does not appear to work. In the FlexGrid source code where rows are constructed (e.g. cvCollectionChanged, bindRows) the Row is directly instantiated and added to the rows array without setting any properties. A row never has allowMerging=true even if the grid has allowMerging=“Cells”.

    Modifying my local copy of wijmo grid I can make these assignments and it “works” (as a quick and dirty proof-of-concept).

    So my question is “was this intentional, or is it a possible oversight?”. Are there horrors awaiting by enabling horizontally merged rows? This is using the standard MergeManager and just ensuring that row properties are set.

    • 2 -

      Regardless of how cells become merged, is there a manner in which to detect whether a cell is merged or not?

    Example use case – styling merged cells.

    • There are no custom classes applied to merged cells.
    • Within an itemFormatter function there is no direct way to determine if the cell is merged. One could possibly access the source data for the entire row and look left and right, but that would require running merge logic again just to format it.

    Any ideas about how this use case might be addressed?

    Thanks.

  • Posted 14 September 2017, 11:15 am EST

    bump

    Any ideas?

  • Posted 14 September 2017, 11:15 am EST

    Hello

    ** Question 1: Is horizontal merging intentionally left out?

    It is not really “left out”. But there is a difference in that you can declare columns, set allowMerging to true, and forget about them.

    If you want to merge rows, you also have to set allowMerging to true, but you can’t do that in markup. But you can do it in response to the collectionChanged event for example:

    [js]flex.collectionView.collectionChanged.addHandler(function() {

    for (var i = 0; i < flex.rows.length; i++) {

    flex.rows[i].allowMerging = true;

    }

    });[/js]

    ** Question 2: Is there a manner in which to detect whether a cell is merged or not?

    Yes, you can call the grid's getMergedRange method. This will return a CellRange that contains the cell passed in or null if the cell is not merged. For example:

    [js]var range = flex.getMergedRange(flex.cells, 3, 3);

    if (!range) {

    console.log('cell (3,3) is not merged');

    } else {

    console.log(wijmo.format('cell (3,3) is merged in this range: ({row},{col})-({row2},{col2})', range));

    }[/js]

    I made a fiddle to demonstrate:

    http://jsfiddle.net/Wijmo5/6yrbhe44/

    I hope this helps.

  • Posted 14 September 2017, 11:15 am EST

    Hi Bernardo. Thank you very much for the answers.

    1. Ok.

    2. Great - fits perfectly with the itemFormatter( panel, r, c ) though it does run the merge logic again just to format it. Probably not an issue, but will keep an eye on performance.

    Thanks again.

  • Posted 14 September 2017, 11:15 am EST

    Very glad to help!

  • Posted 28 November 2018, 7:59 am EST

    Hi bernardo

    I have an issue which is if cell value is 0, I don’t want those cells merged…

    How Can I Prevent it

    Thanks…

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels