如何在制表符数据表中重新加载数据?

时间:2018-07-14 07:45:20

标签: tabulator

我正在尝试使用tabulator加载动态数据,我可以使用以下代码生成表和数据:

result = array.group_by{|i| i['team']}
               .map do |k,v|
                 points = v.map{|i| i['point']}.inject(0, :+)
                 score = v.map{|i| i['score']}.inject(0, :+)
                 {
                   'point' => points, 
                   'score' => score, 
                   'qualified' => points > 5 ? 'yes' : 'no',
                   'team' => k
                 }
               end

但是当我尝试重新加载相同的数据onclick函数时,出现错误:

 $("#example-table").tabulator({
        layout:"fitColumns",

        columns:[ //Define Table Columns
        {title:"Name", field:"name", width:150},
        {title:"Age", field:"age", align:"left", formatter:"progress"},
        {title:"Favourite Color", field:"col"},
        {title:"Date Of Birth", field:"dob", sorter:"date", align:"center"},
    ],
      });
      var tabledata = [
      {id:1, name:"Oli Bob", age:"12", col:"red", dob:""},
      {id:2, name:"Mary May", age:"1", col:"blue", dob:"14/05/1982"},
      {id:3, name:"Christine Lobowski", age:"42", col:"green", dob:"22/05/1982"},
      {id:4, name:"Brendon Philips", age:"125", col:"orange", dob:"01/08/1980"},
      {id:5, name:"Margret Marmajuke", age:"16", col:"yellow", dob:"31/01/1999"},
      ];

    //  $("#example-table").tabulator("setData", []);

      $("#example-table").tabulator("setData", tabledata);

所以我的问题是如何清空表中的数据并重新加载新数据或相同数据

3 个答案:

答案 0 :(得分:1)

我想您想用新数据填充表,因为您需要清空当前表的数据,以查看此链接:

Tabulator Discussion

这里olifolkerd说您可以通过破坏网格并使用以下命令重新创建网格来重新初始化网格:

 $("#example-table").tabulator("destroy");
 $("#example-table").tabulator({...}); 

如果要检查表是否为空,请不要使用此jquery检查制表器数据是否处于活动状态:

 var j = $( "#example-table" ).hasClass( "tabulator" )
     if (j) {
        $("#example-table").tabulator("destroy");

      }
//set new columns
      $("#example-table").tabulator("setColumns", res["column"]);

      //set new data
      $("#example-table").tabulator("setData", res["data"]);

我认为这可以解决您的问题。

答案 1 :(得分:1)

对此的公认答案有些过头,您可以在以下位置调用 setData setColumns 函数创建表后的任何内容。无需先销毁它

'hide the cmd windows from popup
If StrComp(right(WScript.FullName,11),"wscript.exe",1) = 0 Then    
  WScript.Quit CreateObject("WScript.Shell").Run("cscript.exe """ & WScript.ScriptFullName & """", 0, False)
End If

Dim sh : Set sh = CreateObject("WScript.Shell")
'Start VBS-FILE  the full path for script "C:\Users\ENG\MyScriptFile.vbs"
Set Rtn = sh.Exec("wscript.exe C:\Users\ENG\MyScriptFile.vbs")
WScript.Sleep 1000  'stop script 1 sec for waiting OPEN the script
MsgBox "my script file PID  : " & vbTab & Rtn.ProcessID 'Process ID for SCRIPT FILE

'Open EXCEL-FILE New Excel file
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True : Set ObjWorkbook = objExcel.Workbooks.Add()

Set Rtn = sh.Exec("cmd.exe /c tasklist /v /fi ""imagename EQ excel*"" /FO LIST | FIND ""PID:""")
WScript.Sleep 1000   'stop script 1 sec for waiting execute cmd line
MsgBox "my EXCEL FILE " & Rtn.StdOut.ReadLine   'Process ID for EXCEL File

答案 2 :(得分:0)

为此目的定义了一个函数。您可以对数据数组使用 replaceData 方法。或者您可以清除表数据并添加新数据集。

table.clearData();
table.updateOrAddData([{id:1, name:"bob"}, {id:3, name:"steve"}])
.then(function(rows){
    //rows - array of the row components for the rows updated or added
    //run code after data has been updated
})
.catch(function(error){
    //handle error updating data
});

//Replace Data
table.replaceData(tableData)
.then(function(){
    //run code after table has been successfuly updated
})
.catch(function(error){
    //handle error loading data
});

更多关于这里的内容。

[http://tabulator.info/docs/4.0/update][1]