成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

iview Table表格組件無法拆分單元格的解決思路

songze / 2090人閱讀

摘要:因為我們項目中首要的是單元格拆分的,因此以拆分為例。使用函數(shù)對表格組件的表格列配置數(shù)據(jù)進行動態(tài)改造,普通單元格渲染標簽呈現(xiàn)數(shù)據(jù),要拆分的單元格渲染原生標簽最后隱藏嵌套表格的邊框及調(diào)整相關(guān)原生表格樣式。

最近在開發(fā)的Vue項目中,使用了iview第三方UI庫;對于表格組件的需求是最多的,但是在一些特定場景下,發(fā)現(xiàn)iview的表格組件沒有單元格合并與拆分的API,搜了一下發(fā)現(xiàn)很多同學提問關(guān)于iview表格組件的單元格如何拆分和合并的問題。因此某家在此說下我們在項目中如何填的這個坑。
因為我們項目中首要的是單元格拆分的,因此以拆分為例?;舅悸肪褪牵翰辉谠创a層面進行修改;在外部對Table組件進行二次封裝。使用vue render函數(shù)對表格組件的表格列配置數(shù)據(jù)進行動態(tài)改造,普通單元格渲染span標簽呈現(xiàn)數(shù)據(jù),要拆分的單元格渲染原生table標簽;最后隱藏嵌套表格的邊框及調(diào)整相關(guān)原生表格樣式。
這里注意之前打算用iview Table組件進行嵌套,但是發(fā)現(xiàn)修改table組件的樣式非常麻煩,而且沒有效果,一不小心就容易污染全局樣式,因此后來用原生table標簽完美解決樣式不可控問題。

1. 首先對于整體表格的列配置數(shù)據(jù)中有拆分的列進行添加split為true的屬性。

2.對于表格數(shù)據(jù)源進行子表格數(shù)據(jù)定義,也就是用數(shù)組的形式包含子表格數(shù)據(jù)

3.使用vue render函數(shù)動態(tài)渲染改造表格列結(jié)構(gòu),通單元格渲染span標簽呈現(xiàn)數(shù)據(jù),要拆分的單元格渲染原生table標簽。

      let vm = this;
      this.columnsList.forEach(item => {
        // 可編輯單元格
        if (item.editable) {
          item.render = (h, param) => {
            let currentRow = this.thisTableData[param.index];
            if (currentRow.editting) {
              // 正在編輯
              if(item.split){
                    var childArray = currentRow[item.key];
                    var inputArray=[];
                    childArray.forEach(item => {
                          var aa = h("Input", {
                                      style:{
                                          width:"80%",
                                          "margin-top":"10px",
                                          "margin-bottom":"10px"
                                       },
                                      props: {
                                          type: "text",
                                          value: item.child
                                       },
                                      on: {
                                            "on-change" (event) {
                                                  let key = param.column.key;
                                                  var ffffd = vm.edittingStore[param.index][key];
                                                  //item.child = event.target.value;
                                                  //計算當前的索引
                                                  var currentIndex = childArray.indexOf(item);
                                                  //更新數(shù)據(jù)
                                                  vm.edittingStore[param.index][key][currentIndex].child = event.target.value;
                                             }
                                       }
                           });
                          inputArray.push(aa)

                          var currentIndex = childArray.indexOf(item);
                          if(currentIndex!==childArray.length-1){
                                var bb = h("hr",{
                                            style:{
                                                height:"1px",
                                                "background-color":"#e9eaec",
                                                border:"none"
                                             }
                                 })
                                inputArray.push(bb)
                           }
                     })
                    return h("Row",inputArray)
               }
              else
              {          
                    return h("Input", {
                                style:{
                                    width:"80%"
                                },
                                props: {
                                    type: "text",
                                    value: currentRow[item.key]
                                },
                                on: {
                                    "on-change" (event) {
                                        let key = param.column.key;
                                        vm.edittingStore[param.index][key] = event.target.value;
                                    }
                                }
                     });
               }
            } else {
              // 沒在編輯
              if (this.editIncell) {
                // 單元格內(nèi)編輯
                return h("Row", {
                  props: {
                    type: "flex",
                    align: "middle",
                    justify: "center"
                  }
                }, [
                  h("Col", {
                    props: {
                      span: "16"
                    }
                  }, [
                    currentRow.edittingCell[param.column.key] ? cellInput(this, h, param, item) : h("span", currentRow[item.key])
                  ]),
                  h("Col", {
                    props: {
                      span: "8"
                    }
                  }, [
                    currentRow.edittingCell[param.column.key] ? saveIncellEditBtn(this, h, param) : inCellEditBtn(this, h, param)
                  ])
                ]);
              } else {
                // 非單元格內(nèi)編輯
                  if(item.split){

                        if(currentRow.childProject.length==1){
                            var value = currentRow.childProject[0].child;
                            return h("span", value);
                        }

                        //用原生HTML標簽渲染
                        var trAarry=[];
                        var childArray = currentRow[item.key];
                        childArray.forEach(item => {
                              var aa = h("tr",{},[
                                        h("td",{
                                            style:{
                                                border:0,
                                                "text-align":"center"
                                            }
                                        },item.child),
                              ])
                              trAarry.push(aa)
                                    
                              var currentIndex = childArray.indexOf(item);
                              if(currentIndex!==childArray.length-1){
                                    var bb = h("hr",{
                                            style:{
                                                height:"1px",
                                                "background-color":"#e9eaec",
                                                border:"none"
                                             }
                                    })
                                    trAarry.push(bb)
                              }
                        })

                        return h("table",{style:{
                                  "width":"100%",
                                  margin:0,
                                  border:0
                        }},trAarry)
                  }
                  else  return h("span", currentRow[item.key]);
              }
            }
          };
        }
        // 編輯和刪除按鈕
        if (item.handle) {
          item.render = (h, param) => {
            let currentRowData = this.thisTableData[param.index];
            let children = [];
            item.handle.forEach(item => {
              if (item === "edit") {
                children.push(editButton(this, h, currentRowData, param.index));
              } else if (item === "delete") {
                children.push(deleteButton(this, h, currentRowData, param.index));
              }
            });
            return h("div", children);
          };
        }
      });
    } 

4.完美實現(xiàn)了單元格拆分為列的效果。

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/97429.html

相關(guān)文章

  • 精讀《Tableau 探索式模型》

    摘要:比如我們對調(diào)與會怎樣我們得到了三個不同類目近個月的趨勢,之所以是折線圖,因為圖表的維度軸列是連續(xù)的。在正式介紹標記區(qū)域前,先理解一下為何會發(fā)生這種轉(zhuǎn)變表格類組件是雙維度組件,折線圖是單維度組件。 1. 引言 Tableau 探索式分析功能非常強大,各種功能組合似乎有著無限的可能性。 今天筆者會分析這種探索式模型解題思路,一起看看這種探索式分析功能是如何做到的。 2. 精讀 要掌握探索式...

    curried 評論0 收藏0
  • React 實現(xiàn) Table 的思考

    摘要:加這兩個屬性的原因很容易想到,因為我們在寫表格相關(guān)業(yè)務時,樣式里面寫的最多的就是單元格的寬度和對齊方式。然而,寫的表格后粘貼在中,整行的內(nèi)容都在一個單元格里面,用寫的表格則能夠幾乎保持原本的格式,所以我們這次用了原生的來寫表格。 Table 是最常用展示數(shù)據(jù)的方式之一,可是一個產(chǎn)品中往往很多非常類似的 Table,但是我們碰到的情況往往是 Table A 要排序,Table B 不需要...

    ChanceWong 評論0 收藏0
  • iView 發(fā)布 3.0 版本,以及開發(fā)者社區(qū)等 5 款新產(chǎn)品

    摘要:相對時間組件錨點組件面板分割組件分割線組件單元格組件相對時間組件用于表示幾分鐘前幾小時前等相對于此時此刻的時間描述。單元格組件在手機上比較常見,在上則常用于固定的側(cè)邊菜單項。開發(fā)者社區(qū)這是發(fā)布會最勁爆的一款產(chǎn)品了。 showImg(https://segmentfault.com/img/bVbeuj6?w=2864&h=1458); 7 月 28 日,我們成功地召開了 iView 3...

    FreeZinG 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<