- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 621
feat: support rowspan expanded #1278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            crazyair
  wants to merge
  27
  commits into
  react-component:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
crazyair:support-row-span-expanded
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            27 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      45a6c49
              
                feat: support rowspan-expanded
              
              
                crazyair b80b72a
              
                feat: review
              
              
                crazyair 8565bfa
              
                feat: review
              
              
                crazyair 532e524
              
                feat: review
              
              
                crazyair 239af54
              
                feat: review
              
              
                crazyair b5fc268
              
                feat: review
              
              
                crazyair 094972a
              
                feat: review
              
              
                crazyair 2f15e97
              
                feat: rowKeys
              
              
                crazyair 5f41e75
              
                feat: 不改虚拟表格
              
              
                crazyair 668ef08
              
                feat: review
              
              
                crazyair ff959d9
              
                feat: review
              
              
                crazyair 92106b5
              
                feat: review
              
              
                crazyair c3a21ff
              
                feat: review
              
              
                crazyair 0b53334
              
                chore: move keys to cache
              
              
                zombieJ d91920e
              
                chore: simplify code
              
              
                zombieJ dd7d053
              
                chore: clean up
              
              
                zombieJ 2ed330a
              
                chore: adjust offset
              
              
                zombieJ e606eed
              
                feat: 回退 offset 功能
              
              
                crazyair 1cb0013
              
                feat: 去掉 rowSpan > 1 判断,只要 rowSpan = 1 则 +1,如果 rowSpan = undefined 则不 +1
              
              
                crazyair 92432af
              
                fix: conflicts
              
              
                crazyair 227581c
              
                feat: reset
              
              
                crazyair 337c5c9
              
                feat: add sticky
              
              
                crazyair 0bcf3bf
              
                feat: add sticky
              
              
                crazyair a63d6a7
              
                feat: 自动 offset
              
              
                crazyair adf710c
              
                feat: 自动 offset
              
              
                crazyair fa25174
              
                feat: test
              
              
                crazyair dc67020
              
                feat: test
              
              
                crazyair File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| title: expandedRowSpan | ||
| nav: | ||
| title: Demo | ||
| path: /demo | ||
| --- | ||
|  | ||
| <code src="../examples/expandedRowSpan.tsx"></code> | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| title: expandedSticky | ||
| nav: | ||
| title: Demo | ||
| path: /demo | ||
| --- | ||
|  | ||
| <code src="../examples/expandedSticky.tsx"></code> | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import React from 'react'; | ||
| import Table from 'rc-table'; | ||
| import '../../assets/index.less'; | ||
| import type { ColumnsType } from '@/interface'; | ||
|  | ||
| const columns: ColumnsType = [ | ||
| { | ||
| title: '手机号', | ||
| dataIndex: 'a', | ||
| colSpan: 2, | ||
| width: 100, | ||
| onCell: (_, index) => { | ||
| const props: React.TdHTMLAttributes<HTMLTableCellElement> = {}; | ||
| if (index === 0) props.rowSpan = 1; | ||
| if (index === 1) props.rowSpan = 4; | ||
| if (index === 2) props.rowSpan = 0; | ||
| if (index === 3) props.rowSpan = 0; | ||
| if (index === 4) props.rowSpan = 0; | ||
| if (index === 5) props.rowSpan = undefined; | ||
| return props; | ||
| }, | ||
| }, | ||
| { title: '电话', dataIndex: 'b', colSpan: 0, width: 100 }, | ||
| Table.EXPAND_COLUMN, | ||
| { title: 'Name', dataIndex: 'c', width: 100 }, | ||
| { title: 'Address', dataIndex: 'd', width: 200 }, | ||
| ]; | ||
|  | ||
| const data = [ | ||
| { a: '12313132132', b: '0571-43243256', c: '小二', d: '文零西路', e: 'Male', key: 'z' }, | ||
| { a: '13812340987', b: '0571-12345678', c: '张三', d: '文一西路', e: 'Male', key: 'a' }, | ||
| { a: '13812340987', b: '0571-12345678', c: '张夫人', d: '文一西路', e: 'Female', key: 'b' }, | ||
| { a: '13812340987', b: '0571-099877', c: '李四', d: '文二西路', e: 'Male', key: 'c' }, | ||
| { a: '13812340987', b: '0571-099877', c: '李四', d: '文二西路', e: 'Male', key: 'd' }, | ||
| { a: '1381200008888', b: '0571-099877', c: '王五', d: '文二西路', e: 'Male', key: 'e' }, | ||
| ]; | ||
|  | ||
| const Demo = () => ( | ||
| <div> | ||
| <h2>expanded & rowSpan</h2> | ||
| <Table<Record<string, any>> | ||
| rowKey="key" | ||
| columns={columns} | ||
| data={data} | ||
| expandable={{ expandedRowRender: record => <p style={{ margin: 0 }}>{record.key}</p> }} | ||
| className="table" | ||
| /> | ||
| </div> | ||
| ); | ||
|  | ||
| export default Demo; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import React, { useState } from 'react'; | ||
| import type { ColumnType } from 'rc-table'; | ||
| import Table from 'rc-table'; | ||
| import '../../assets/index.less'; | ||
|  | ||
| const Demo = () => { | ||
| const [expandedRowKeys, setExpandedRowKeys] = useState<readonly React.Key[]>([]); | ||
|  | ||
| const columns: ColumnType<Record<string, any>>[] = [ | ||
| // { title: '分割', dataIndex: 'ca' }, | ||
| { | ||
| title: '手机号', | ||
| dataIndex: 'a', | ||
| width: 100, | ||
| fixed: 'left', | ||
| onCell: (_, index) => { | ||
| const props: React.TdHTMLAttributes<HTMLTableCellElement> = {}; | ||
| if (index === 0) props.rowSpan = 1; | ||
| if (index === 1) props.rowSpan = 2; | ||
| if (index === 2) props.rowSpan = 0; | ||
| return props; | ||
| }, | ||
| }, | ||
| Table.EXPAND_COLUMN, | ||
| { title: 'Name', dataIndex: 'c' }, | ||
| { title: 'Address', fixed: 'right', dataIndex: 'd', width: 200 }, | ||
| ]; | ||
|  | ||
| return ( | ||
| <div | ||
| style={{ | ||
| height: 10000, | ||
| }} | ||
| > | ||
| <h2>expanded & sticky</h2> | ||
| <Table<Record<string, any>> | ||
| rowKey="key" | ||
| sticky | ||
| scroll={{ x: 800 }} | ||
| columns={columns} | ||
| data={[ | ||
| { key: 'a', a: '12313132132', c: '小二', d: '文零西路' }, | ||
| { key: 'b', a: '13812340987', c: '张三', d: '文一西路' }, | ||
| { key: 'c', a: '13812340987', c: '张夫', d: '文二西路' }, | ||
| ]} | ||
| expandable={{ | ||
| expandedRowKeys, | ||
| onExpandedRowsChange: keys => setExpandedRowKeys(keys), | ||
| expandedRowRender: record => <p style={{ margin: 0 }}>{record.key}</p>, | ||
| }} | ||
| className="table" | ||
| /> | ||
| </div> | ||
| ); | ||
| }; | ||
|  | ||
| export default Demo; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
确保 colSpan 不会为负值
当计算展开行的
colSpan时,需要确保结果不会为负值:<ExpandedRow expanded={expanded} className={cls( `${prefixCls}-expanded-row`, `${prefixCls}-expanded-row-level-${indent + 1}`, expandedClsName, )} prefixCls={prefixCls} component={RowComponent} cellComponent={cellComponent} offsetWidth={offsetData.offsetWidth} - colSpan={flattenColumns.length - offsetData.offsetColumn} + colSpan={Math.max(1, flattenColumns.length - offsetData.offsetColumn)} isEmpty={false} >当
offsetData.offsetColumn大于或等于flattenColumns.length时,计算结果可能为零或负值,这将导致意外的渲染结果。📝 Committable suggestion
🤖 Prompt for AI Agents