ag-Grid行未删除

时间:2018-10-04 20:42:06

标签: angular ag-grid

我试图像这样从我的ag-Grid删除一行:

let alertRow : RowNode = this.gridApi.getRowNode(rowIndex);
console.log(alertRow);
this.gridApi.updateRowData({remove: [alertRow]});

它给了我这个错误:

  

ag-Grid:找不到数据项,因为找不到对象

我可以在控制台中看到RowNode是正确的节点并存在。我还可以使用updateRowData()来添加新行,但是尝试删除会出现此错误。

我正在Angular 6组件中使用ag-Grid。

为什么删除无效?

3 个答案:

答案 0 :(得分:1)

代替updateRowData({remove:[alerRow]})

updateRowData({remove:[alertRow.data]}))

答案 1 :(得分:0)

不能完全确定这是添加到un.spike's answer的正确位置/方式,但是如果您使用getSelectedNodes方法来获取要删除的数据,则语法为稍有不同(需要索引到选定的节点)。

(均假设您使用的是单行选择)

getSelectedNodes

ARG BRA CHL COL MEX PER
NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
4,18006E+25 6,71826E+23 -4,22578E+22    NA  8,04238E+23 4,03712E+21
6,71826E+23 1,98743E+22 -1,09244E+21    NA  1,97446E+22 1,47238E+20
-4,22578E+22    -1,09244E+21    1,0256E+21  NA  -2,7575E+21 -2,07661E+19
NA  NA  NA  NA  NA  NA
8,04238E+23 1,97446E+22 -2,7575E+21 NA  2,74899E+22 1,97806E+20
4,03712E+21 1,47238E+20 -2,07661E+19    NA  1,97806E+20 1,82987E+18
4,18935E+25 6,91787E+23 -4,24427E+22    NA  8,27556E+23 4,02872E+21
6,91787E+23 2,35932E+22 -1,01681E+21    NA  2,34895E+22 1,45014E+20
-4,24427E+22    -1,01681E+21    1,00257E+21 NA  -2,54755E+21    -2,06643E+19
NA  NA  NA  NA  NA  NA
8,27556E+23 2,34895E+22 -2,54755E+21    NA  3,05325E+22 1,94766E+20
4,02872E+21 1,45014E+20 -2,06643E+19    NA  1,94766E+20 1,83032E+18
3,85787E+25 5,85158E+23 -1,76841E+22    NA  7,61258E+23 3,82149E+21
5,85158E+23 2,0216E+22  -1,14113E+20    NA  2,13742E+22 1,368E+20
-1,76841E+22    -1,14113E+20    1,03154E+21 NA  -2,01752E+21    -2,22328E+19
NA  NA  NA  NA  NA  NA
7,61258E+23 2,13742E+22 -2,01752E+21    NA  2,92122E+22 1,90114E+20
3,82149E+21 1,368E+20   -2,22328E+19    NA  1,90114E+20 1,86277E+18
3,9646E+25  6,25316E+23 -1,25623E+22    NA  7,9184E+23  3,41683E+21
6,25316E+23 2,15226E+22 4,14541E+19 NA  2,21299E+22 1,17107E+20
-1,25623E+22    4,14541E+19 1,04937E+21 NA  -1,94256E+21    -2,49868E+19
NA  NA  NA  NA  NA  NA
7,9184E+23  2,21299E+22 -1,94256E+21    NA  2,93251E+22 1,69884E+20
3,41683E+21 1,17107E+20 -2,49868E+19    NA  1,69884E+20 1,91854E+18
4,00608E+25 5,28522E+23 -3,98103E+22    NA  7,25966E+23 3,39882E+21
5,28522E+23 1,92089E+22 -9,52424E+20    NA  2,10224E+22 1,22107E+20
-3,98103E+22    -9,52424E+20    6,68445E+20 NA  -2,48102E+21    -2,35684E+19
NA  NA  NA  NA  NA  NA
7,25966E+23 2,10224E+22 -2,48102E+21    NA  2,88805E+22 1,73272E+20
3,39882E+21 1,22107E+20 -2,35684E+19    NA  1,73272E+20 1,9193E+18
3,92814E+25 5,14096E+23 -5,75873E+22    NA  7,36136E+23 3,64696E+21
5,14096E+23 1,89508E+22 -1,22008E+21    NA  2,11875E+22 1,26049E+20
-5,75873E+22    -1,22008E+21    6,86608E+20 NA  -2,40918E+21    -2,24004E+19
NA  NA  NA  NA  NA  NA
7,36136E+23 2,11875E+22 -2,40918E+21    NA  2,88083E+22 1,71732E+20
3,64696E+21 1,26049E+20 -2,24004E+19    NA  1,71732E+20 1,88792E+18
4,08848E+25 5,97299E+23 -7,45317E+22    NA  7,26498E+23 5,94296E+21
5,97299E+23 1,78012E+22 -1,24418E+21    NA  2,06217E+22 1,19741E+20
-7,45317E+22    -1,24418E+21    7,31907E+20 NA  -2,29706E+21    -2,70411E+19
NA  NA  NA  NA  NA  NA
7,26498E+23 2,06217E+22 -2,29706E+21    NA  2,88655E+22 1,56424E+20
5,94296E+21 1,19741E+20 -2,70411E+19    NA  1,56424E+20 2,29709E+18
4,1233E+25  6,03197E+23 -9,96874E+22    NA  7,16052E+23 5,78562E+21
6,03197E+23 1,77172E+22 -1,18932E+21    NA  2,03625E+22 1,14611E+20
-9,96874E+22    -1,18932E+21    1,29102E+21 NA  -1,32713E+21    -9,22348E+18
NA  NA  NA  NA  NA  NA
7,16052E+23 2,03625E+22 -1,32713E+21    NA  2,9142E+22  1,60041E+20
5,78562E+21 1,14611E+20 -9,22348E+18    NA  1,60041E+20 2,33512E+18
4,73019E+25 6,10664E+23 -9,04172E+22    NA  6,62695E+23 5,83314E+21
6,10664E+23 1,70057E+22 -1,3253E+21 NA  2,0684E+22  1,09479E+20
-9,04172E+22    -1,3253E+21 1,27504E+21 NA  -1,32946E+21    -1,02123E+19
NA  NA  NA  NA  NA  NA
6,62695E+23 2,0684E+22  -1,32946E+21    NA  2,94032E+22 1,62411E+20
5,83314E+21 1,09479E+20 -1,02123E+19    NA  1,62411E+20 2,29811E+18
5,30052E+25 6,04344E+23 -7,34753E+22    NA  7,14991E+23 6,6555E+21
6,04344E+23 1,70124E+22 -1,34715E+21    NA  2,06165E+22 1,08439E+20
-7,34753E+22    -1,34715E+21    1,29623E+21 NA  -1,26418E+21    -8,98516E+18
NA  NA  NA  NA  NA  NA
7,14991E+23 2,06165E+22 -1,26418E+21    NA  2,96043E+22 1,66194E+20
6,6555E+21  1,08439E+20 -8,98516E+18    NA  1,66194E+20 2,36596E+18
5,07653E+25 5,48778E+23 -6,83696E+22    NA  6,59224E+23 6,91647E+21
5,48778E+23 1,75869E+22 -1,41687E+21    NA  2,05055E+22 1,04693E+20
-6,83696E+22    -1,41687E+21    1,30433E+21 NA  -1,265E+21  -8,55242E+18
NA  NA  NA  NA  NA  NA
6,59224E+23 2,05055E+22 -1,265E+21  NA  2,90448E+22 1,66034E+20
6,91647E+21 1,04693E+20 -8,55242E+18    NA  1,66034E+20 2,38904E+18
4,0635E+25  1,46155E+23 -2,35357E+22    NA  1,26813E+23 3,49961E+21
1,46155E+23 2,4681E+22  -1,91461E+21    NA  2,8475E+22  1,85151E+20
-2,35357E+22    -1,91461E+21    1,33092E+21 NA  -1,78389E+21    -1,47757E+19
NA  NA  NA  NA  NA  NA
1,26813E+23 2,8475E+22  -1,78389E+21    NA  3,78034E+22 2,59213E+20
3,49961E+21 1,85151E+20 -1,47757E+19    NA  2,59213E+20 3,26149E+18
4,85007E+25 -2,91619E+23    7,94719E+22 NA  -5,96409E+23    -4,64117E+21
-2,91619E+23    2,59602E+22 -2,52874E+21    NA  3,04069E+22 2,15855E+20
7,94719E+22 -2,52874E+21    1,54485E+21 NA  -2,75823E+21    -2,77292E+19
NA  NA  NA  NA  NA  NA
-5,96409E+23    3,04069E+22 -2,75823E+21    NA  4,06938E+22 3,06616E+20
-4,64117E+21    2,15855E+20 -2,77292E+19    NA  3,06616E+20 3,95897E+18
5,51321E+25 -2,99987E+23    7,29482E+22 NA  -5,36394E+23    -3,52559E+21
-2,99987E+23    2,30985E+22 -2,45506E+21    NA  2,82538E+22 2,22119E+20
7,29482E+22 -2,45506E+21    1,54978E+21 NA  -2,76993E+21    -2,90015E+19
NA  NA  NA  NA  NA  NA
-5,36394E+23    2,82538E+22 -2,76993E+21    NA  3,97345E+22 3,22261E+20
-3,52559E+21    2,22119E+20 -2,90015E+19    NA  3,22261E+20 4,12615E+18
5,59737E+25 -3,29301E+23    8,62907E+22 NA  -4,90529E+23    -3,58299E+21
-3,29301E+23    2,39807E+22 -3,16772E+21    NA  2,63368E+22 2,27166E+20
8,62907E+22 -3,16772E+21    1,31833E+21 NA  -2,61378E+21    -2,44679E+19
NA  NA  NA  NA  NA  NA
-4,90529E+23    2,63368E+22 -2,61378E+21    NA  4,1498E+22  3,26149E+20
-3,58299E+21    2,27166E+20 -2,44679E+19    NA  3,26149E+20 4,06317E+18
5,3211E+25  -3,81566E+23    8,44886E+22 NA  -5,37471E+23    -3,06162E+21
-3,81566E+23    2,3009E+22  -3,15711E+21    NA  2,53069E+22 2,37257E+20
8,44886E+22 -3,15711E+21    1,43445E+21 NA  -3,01647E+21    -2,3529E+19
NA  NA  NA  NA  NA  NA
-5,37471E+23    2,53069E+22 -3,01647E+21    NA  4,18807E+22 3,33108E+20
-3,06162E+21    2,37257E+20 -2,3529E+19 NA  3,33108E+20 3,96783E+18
5,43594E+25 -3,6416E+23 6,59128E+22 NA  -5,01704E+23    -2,36481E+21
-3,6416E+23 2,28284E+22 -3,13074E+21    NA  2,49901E+22 2,37499E+20
6,59128E+22 -3,13074E+21    1,52162E+21 NA  -3,00002E+21    -2,76515E+19
NA  NA  NA  NA  NA  NA
-5,01704E+23    2,49901E+22 -3,00002E+21    NA  4,13349E+22 3,3487E+20
-2,36481E+21    2,37499E+20 -2,76515E+19    NA  3,3487E+20  4,15105E+18
5,80244E+25 -2,05411E+23    1,66954E+23 NA  -3,87726E+23    -2,47075E+21
-2,05411E+23    2,79703E+22 -5,7412E+20 NA  2,86258E+22 2,34915E+20
1,66954E+23 -5,7412E+20 2,39735E+21 NA  -1,22328E+21    -2,8468E+19
NA  NA  NA  NA  NA  NA
-3,87726E+23    2,86258E+22 -1,22328E+21    NA  4,39031E+22 3,3308E+20
-2,47075E+21    2,34915E+20 -2,8468E+19 NA  3,3308E+20  4,1518E+18
5,65171E+25 -2,01614E+23    1,74186E+23 NA  -3,44895E+23    -3,52899E+21
-2,01614E+23    2,84056E+22 -5,63959E+20    NA  2,99465E+22 2,2302E+20
1,74186E+23 -5,63959E+20    2,36445E+21 NA  -1,33765E+21    -2,43193E+19
NA  NA  NA  NA  NA  NA
-3,44895E+23    2,99465E+22 -1,33765E+21    NA  4,72737E+22 3,16389E+20
-3,52899E+21    2,2302E+20  -2,43193E+19    NA  3,16389E+20 3,88547E+18
5,65464E+25 -2,04203E+23    1,79731E+23 NA  -3,23146E+23    -3,31102E+21
-2,04203E+23    2,86233E+22 -9,11793E+20    NA  2,84502E+22 2,08136E+20
1,79731E+23 -9,11793E+20    1,6589E+21  NA  -2,48941E+21    -3,72275E+19
NA  NA  NA  NA  NA  NA
-3,23146E+23    2,84502E+22 -2,48941E+21    NA  4,76086E+22 3,15644E+20
-3,31102E+21    2,08136E+20 -3,72275E+19    NA  3,15644E+20 3,83584E+18
5,16898E+25 -2,89171E+23    1,45562E+23 NA  -2,63754E+23    -3,04789E+21
-2,89171E+23    2,81558E+22 -1,11338E+21    NA  2,8664E+22  2,07773E+20
1,45562E+23 -1,11338E+21    1,57255E+21 NA  -2,39241E+21    -3,73071E+19
NA  NA  NA  NA  NA  NA
-2,63754E+23    2,8664E+22  -2,39241E+21    NA  4,75506E+22 3,16448E+20
-3,04789E+21    2,07773E+20 -3,73071E+19    NA  3,16448E+20 3,84579E+18
5,33477E+25 -2,02001E+23    1,73467E+23 NA  -2,07893E+23    -3,83605E+21
-2,02001E+23    2,80346E+22 -9,49626E+20    NA  2,9042E+22  2,14503E+20
1,73467E+23 -9,49626E+20    1,68109E+21 NA  -2,16123E+21    -3,72266E+19
NA  NA  NA  NA  NA  NA
-2,07893E+23    2,9042E+22  -2,16123E+21    NA  4,80407E+22 3,16095E+20
-3,83605E+21    2,14503E+20 -3,72266E+19    NA  3,16095E+20 3,72724E+18
6,04335E+25 -9,97361E+22    1,5349E+23  NA  2,35101E+22 -3,75406E+21
-9,97361E+22    2,84581E+22 -9,23729E+20    NA  3,10961E+22 2,17358E+20
1,5349E+23  -9,23729E+20    1,64361E+21 NA  -2,4298E+21 -3,79567E+19
NA  NA  NA  NA  NA  NA
2,35101E+22 3,10961E+22 -2,4298E+21 NA  5,40272E+22 3,20814E+20
-3,75406E+21    2,17358E+20 -3,79567E+19    NA  3,20814E+20 3,72554E+18
7,60131E+25 5,44446E+23 1,19996E+23 NA  9,69418E+23 4,98478E+21
5,44446E+23 2,32553E+22 1,11325E+21 NA  2,77437E+22 1,86029E+20
1,19996E+23 1,11325E+21 1,34784E+21 NA  1,00487E+20 -1,4542E+19
NA  NA  NA  NA  NA  NA
9,69418E+23 2,77437E+22 1,00487E+20 NA  5,48227E+22 3,27687E+20
4,98478E+21 1,86029E+20 -1,4542E+19 NA  3,27687E+20 3,78463E+18
8,41221E+25 1,15703E+24 2,32703E+21 NA  1,99238E+24 1,26813E+22
1,15703E+24 2,5327E+22  4,4707E+20  NA  3,17636E+22 1,88573E+20
2,32703E+21 4,4707E+20  1,5257E+21  NA  -1,11622E+21    -1,85433E+19
NA  NA  NA  NA  NA  NA
1,99238E+24 3,17636E+22 -1,11622E+21    NA  6,24642E+22 3,39273E+20
1,26813E+22 1,88573E+20 -1,85433E+19    NA  3,39273E+20 3,50904E+18
7,69302E+25 1,17456E+24 -5,46765E+21    NA  1,9026E+24  1,13167E+22
1,17456E+24 2,73007E+22 3,76748E+20 NA  3,27827E+22 1,75283E+20
-5,46765E+21    3,76748E+20 1,52121E+21 NA  -1,24897E+21    -1,92862E+19
NA  NA  NA  NA  NA  NA
1,9026E+24  3,27827E+22 -1,24897E+21    NA  6,1661E+22  3,15644E+20
1,13167E+22 1,75283E+20 -1,92862E+19    NA  3,15644E+20 3,38705E+18
7,98512E+25 1,19401E+24 -1,84872E+22    NA  1,94187E+24 1,1232E+22
1,19401E+24 2,5182E+22  5,00229E+20 NA  3,43303E+22 1,77164E+20
-1,84872E+22    5,00229E+20 1,55959E+21 NA  -1,54426E+21    -1,9137E+19
NA  NA  NA  NA  NA  NA
1,94187E+24 3,43303E+22 -1,54426E+21    NA  6,14535E+22 3,13105E+20
1,1232E+22  1,77164E+20 -1,9137E+19 NA  3,13105E+20 3,38685E+18
8,72812E+25 1,14668E+24 7,63586E+21 NA  2,12126E+24 1,06327E+22
1,14668E+24 2,52032E+22 7,69616E+19 NA  3,38753E+22 1,79316E+20
7,63586E+21 7,69616E+19 1,41599E+21 NA  -2,83221E+20    -2,27712E+19
NA  NA  NA  NA  NA  NA
2,12126E+24 3,38753E+22 -2,83221E+20    NA  6,40969E+22 3,02724E+20
1,06327E+22 1,79316E+20 -2,27712E+19    NA  3,02724E+20 3,42529E+18

而且,为了“完整性”,
getSelectedRows (即使API建议使用const selectedNode = this.gridApi.getSelectedNodes(); this.gridApi.updateRowData({ remove: [selectedNode[0].data] });

getSelectedNodes

答案 2 :(得分:0)

如果使用vue.js,则可以使用以下代码行:

  1. 获取选择的行const selectedRow = this.gridApi.getFocusedCell()

  2. 通过选择行const node = this.gridApi.getRowNode(selectedRow.rowIndex)

    获取节点
  3. ApplyTransaction通过节点的数据删除该节点。 this.gridApi.applyTransaction({ remove: [node.data] })