Atmos206 / ui-grid-custom-cell-select

UI Grid 3.x/4.x Custom Copy/Paste Selection Plugin
8 stars 5 forks source link

Including Column Headers #1

Open ElliotPsyIT opened 7 years ago

ElliotPsyIT commented 7 years ago

First, thank you @Atmos206 for the excellent work on ui-grid-custom-cell-select.

I'm using it in a project where I needed to include column headers by default. I simply patched the ui-grid-custom-cell-select directive for my purposes.

It's not a general solution since you might want to have an option to include headers or not (maybe a configurable provider) rather than include headers by default. And I did modify the copyData array assignment, which I probably shouldn't do.

In any case, I thought I'd briefly share the added code here FWIW. Perhaps someone might have a use for it as a quick and dirty option.

I'm a newbie, so any comments on the code or obvious bugs to be pointed out are welcome.

// copy headers from selected cells into copyData array,, then add the cells' data 
_scope.ugCustomSelect.copyData = createCopyHeaders(indexMap.col.start, indexMap.col.end)
_scope.ugCustomSelect.copyData += createCopyData(_scope.ugCustomSelect.selectedCells,

// copy headers fn
function createCopyHeaders(colStart, colEnd){
    var visibleCols = grid.renderContainers.body.renderedColumns;
    var numCols = colEnd - colStart;
    var columnHeaders = ''
    for (var ci = colStart; ci <= colEnd; ci++) {
        var currentCol = visibleCols[ci];
        columnHeaders += currentCol.displayName;
        if (ci !== colEnd) {
            columnHeaders += '\t';
        }
    }
    return columnHeaders + '\n';
}
Atmos206 commented 7 years ago

Thanks for posting a workaround. Will look into solution implementation as time permits.