react easyui datagrid/treegrid的几个问题

本文探讨了在使用EasyUI的React版本时,如何有效地添加列和插入新行的问题。作者分享了调整column的方法,以及尝试解决新增行后焦点定位的技巧,为遇到同样困扰的开发者提供了解决方案。

easyui的react版本比较难用。

1.如何增加column?

    ...........
    render(){
      //字段标题需要用当前语言翻译,不能写在render外部
      let columns=aFields.map((field)=>{
        return <GridColumn key={field} field={field} title={t(field)} 
          rowspan={(field=='DisplayValue')?1:2} 
          colspan={(field=='DisplayValue')?aLCIDs.length:1}
          editable={true}
          sortable={(field=='DisplayValue')?false:true}
          editor={({ row }) => ((field=='SortNumber'||field=='SeqNo')?
            <NumberBox value={row[field]} precision={0}></NumberBox>:
            <TextBox value={row[field]}></TextBox>
          )}
          width={fieldWidth[field]}>
        </GridColumn>
      });
      let LCIDColumns=aLCIDs.map((field)=>{
        return <GridColumn key={field} field={field} sortable={true}
          editable={true}
          title={t(field)}>
        </GridColumn>
      });
      return (
          <div>
            <div>{t('Data Dictionary Editor')}</div>
            <div className="dialog-button">
              <LinkButton className="c1" onClick={this.s2t}>{t('s2t')}</LinkButton>
              <LinkButton onClick={this.t2s}>{t('t2s')}</LinkButton>
              <LinkButton iconCls="icon-add" onClick={this.askAddLCID}>Add Language</LinkButton>
              <LinkButton iconCls="icon-add" onClick={this.appendRow}>Append Row</LinkButton>
            </div>
            <div>
                <TreeGrid data={this.state.data} idField="DDKey" treeField="DDKey" 
                  ref={this.tree}
                  pagination={true} filterable={true} editMode="cell" clickToEdit={true}
                  onFilterChange={this.onFilterChange}
                  onRowSelect={this.onRowSelect}
                >
                  <GridColumnGroup>
                    <GridHeaderRow>
                      <GridColumn align="center" filterable={false} width={40}
                        cellCss="datagrid-td-rownumber" rowspan={2} sortable={false}
                        render={({rowIndex}) => (
                          <span>{rowIndex+1}</span>
                        )}
                      />
                      {columns}
                    </GridHeaderRow>
                    <GridHeaderRow>
                      {LCIDColumns}
                    </GridHeaderRow>
                  </GridColumnGroup>
                </TreeGrid>
            </div>
            <ComSelectLCID ref={this.dialog_selectLCID} onOK={this.doAddLCID} title='add one language'></ComSelectLCID>
          </div>
      )
    }
    ..........
    doAddLCID(LCID){
      console.log(this.tree.current);
      aLCIDs.push(333);
      this.forceUpdate();
      this.tree.current.forceUpdate();
    }

column是增加了,但是filter面板和资料区都没有刷新,不行。

 easyui文档不全面,通过console debug找到个changeColumns函数,改为:

    doAddLCID(LCID){
      console.log(this.tree.current);
      aLCIDs.push(333);
      this.forceUpdate();
      this.tree.current.changeColumns();
    }

 ok,显示正常。

2.如何新增row?选中新增的row,聚焦到新增的row光标闪烁。

    appendRow(){
      this.state.data.push({});
      this.tree.current.setData(this.state.data);
      //this.tree.current.forceUpdate();
      //如何显示新增的这行?切换到最后一页
      this.tree.current.setState({pageNumber:1000});
      //this.tree.current.navRow({});
      this.tree.current.selectRow({});
      //this.tree.current.scrollTop({});
      //如何焦点落在新增的这行,光标闪烁
      this.tree.current.doEnter();
      this.tree.current.beginEdit({},this.tree.current.state.centerColumns[1]);
    }

 焦点没有聚焦到新增的行,光标没有闪烁。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

火星牛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值