【问题标题】:Can I use getState() to get grid column header names (the visible names)?我可以使用 getState() 来获取网格列标题名称(可见名称)吗?
【发布时间】:2012-06-19 06:48:38
【问题描述】:

我可以使用 getState() 来获取网格列标题名称(可见名称)吗?

【问题讨论】:

    标签: extjs4.1


    【解决方案1】:

    没有。但是这个非常复杂的函数会将它们作为数组返回给你:

    function getGridClipboardText(grid){
            var columns = grid.columns,
                headerData = [],
                subHeaderData = [],
                dataIndex = [],
                du = Sms.dataUtilities,
                columnCount = columns.length,
                startIndex = 0,
                headerText,
                subColumnCount,
                visibleSubColumns,
                columnCollection,
                i, j, col, subCol;
    
            // If grid has a row expander plugin, skip the first column
            if(grid.expanderDataIndex){
                startIndex = 1;
            }
    
            // Collect the header titles
            for(i = startIndex; i < columnCount; i++){
                col = columns[i];
                if(!col.hidden){
                    headerText = du.getInnerHtml(col.text);
    
                    // Flatten the data index references to a single array
                    if(col.dataIndex){
                        dataIndex.push({
                            dataIndex: col.dataIndex,
                            clipboard: col.clipboard
                        });
                    }
    
                    // If the column has sub-columns, handle them
                    // IMPORTANT: This function only supports two levels of headers.
                    // When upgrading to fully-nested headers, use a recursive algorithm.
                    if(col.items && col.xtype !== "actioncolumn"){
                        if(Ext.isArray(col.items)){
                            columnCollection = new Ext.util.MixedCollection(false);
                            columnCollection.addAll(col.items);
                        }
                        else{
                            columnCollection = col.items;
                        }
    
                        subColumnCount = columnCollection.getCount();
                        visibleSubColumns = 0;
                        for(j = 0; j < subColumnCount; j++){
                            subCol = columnCollection.getAt(j);
                            if(!subCol.hidden){
                                visibleSubColumns++;
                                subHeaderData.push(du.getInnerHtml(subCol.text));
    
                                if(subCol.dataIndex){
                                    dataIndex.push({
                                        dataIndex: subCol.dataIndex,
                                        clipboard: col.clipboard
                                    });
                                }
                            }
                        }
    
                        // If there are no sub-columns, but there could be, create a spacer
                        // in the array to keep everything lined up
                        if(subColumnCount === 0){
                            subHeaderData.push("");
                        }
    
                        // Pad the main header with extra tabs to account for the sub-columns
                        for(j = 0; j < visibleSubColumns - 1; j++){
                            headerText += "\t";
                        }
                    }
    
                    headerData.push(headerText);
                }
            }
    
            return headerData;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-10
      • 2023-03-16
      • 1970-01-01
      相关资源
      最近更新 更多