Dear NSB team,
I’m trying to use two different datatables in two different forms, but when I add the second one,it works well, but the first doesn’t work anymore. I simply created a project with 3 forms (code attached), using the example on section 3 Datatable, obviously changing the occurrences of variables and controls.
As I said, one work fine, the other not.
What’s the problem? What I miss? I’m getting crazy.
Thanks in advance.
Best Regards
Rotondi Alex
Code->
First form:
Function BtnForm1_onclick()
ChangeForm(Form11)
End Function
Function BtnForm2_onclick()
ChangeForm(Form12)
End Function
Form11:
JavaScript
// an array of arrays. One array for each row.
var data1 = [
["Prescott Bartlett", "Technical Author", "London", "3606", "2011/05/07", "$145,000"],
["Gavin Cortez", "Team Leader", "San Francisco", "2860", "2008/10/26", "$235,500"],
["Martena Mccray", "Post-Sales support", "Edinburgh", "8240", "2011/03/09", "$324,050"],
["Unity Butler", "Marketing Designer", "San Francisco", "5384", "2009/12/09", "$85,675"]
];
var dataJson = JSON.stringify(data1);
// class values are here:
// http://getbootstrap.com/css/#type-alignment
var columns1 = [
{title: "Name"},
{title: "Position"},
{title: "Office"},
{title: "Extn."},
{title: "Start date"},
{title: "Salary", class:"text-right"}
];
End JavaScript
Function Main()
updateTable()
End Function
Function DataTable1_onclick(event)
If typeof(event.target._DT_CellIndex) <> "object" Then return
Dim row, col
row = event.target._DT_CellIndex.row
col = event.target._DT_CellIndex.column
MsgBox "Click on " & row & ", " & col & ". Value is '" & data1[row][col] & "'."
End Function
Function updateTable()
DataTable1.settings.columns = columns1
DataTable1.settings.data = data1
DataTable1.build()
End Function
Function Button11_onclick()
data1[0][0] += "+" 'Just to make a change to the table
updateTable()
End Function
Function Button21_onclick()
var table = $("#DataTable1").DataTable()
table.clear()
DataTable1.settings.data = JSON.parse(dataJson)
DataTable1.settings.data[0][0] = "George"
SetTimeout(loadTable, 50)
End Function
Function loadTable()
var table = $("#DataTable1").DataTable()
table.rows.add(DataTable1.settings.data).draw()
End Function
Function Button3_onclick()
Dim table
table = $("#DataTable1").DataTable()
$(table.rows().nodes()).removeClass("highlight")
$(table.cells().nodes()).removeClass("highlight")
$(table.column(2).nodes()).addClass("highlight")
End Function
Function Button4_onclick()
Dim table
table = $("#DataTable1").DataTable()
$(table.rows().nodes()).removeClass("highlight")
$(table.cells().nodes()).removeClass("highlight")
$(table.row(2).nodes()).addClass("highlight")
End Function
Function Fliptoggle1_onchange()
DataTable1.settings.ordering = Fliptoggle1.value
updateTable()
End Function
Function Fliptoggle4_onchange()
DataTable1.settings.paging = Fliptoggle4.value
updateTable()
End Function
Function Fliptoggle5_onchange()
DataTable1.settings.searching = Fliptoggle5.value
updateTable()
End Function
Form12:
JavaScript
// an array of arrays. One array for each row.
var data2 = [
["Tiger Nixon", "System Architect", "Edinburgh", "5421", "2011/04/25", "$320,800"],
["Gavin Cortez", "Team Leader", "San Francisco", "2860", "2008/10/26", "$235,500"],
["Martena Mccray", "Post-Sales support", "Edinburgh", "8240", "2011/03/09", "$324,050"],
["Unity Butler", "Marketing Designer", "San Francisco", "5384", "2009/12/09", "$85,675"]
];
var dataJson2 = JSON.stringify(data1);
// class values are here:
// http://getbootstrap.com/css/#type-alignment
var columns2 = [
{title: "Name"},
{title: "Position"},
{title: "Office"},
{title: "Extn."},
{title: "Start date"},
{title: "Salary", class:"text-right"}
];
End JavaScript
Function Main()
updateTable2()
End Function
Function DataTable11_onclick(event)
If typeof(event.target._DT_CellIndex) <> "object" Then return
Dim row, col
row = event.target._DT_CellIndex.row
col = event.target._DT_CellIndex.column
MsgBox "Click on " & row & ", " & col & ". Value is '" & data2[row][col] & "'."
End Function
Function updateTable2()
DataTable11.settings.columns = columns2
DataTable11.settings.data = data2
DataTable11.build()
End Function
Function Button1_onclick()
data2[0][0] += "+" 'Just to make a change to the table
updateTable2()
End Function
Function Button2_onclick()
var table = $("#DataTable11").DataTable()
table.clear()
DataTable2.settings.data = JSON.parse(dataJson2)
DataTable2.settings.data[0][0] = "Andy"
SetTimeout(loadTable2, 50)
End Function
Function loadTable2()
var table = $("#DataTable11").DataTable()
table.rows.add(DataTable11.settings.data).draw()
End Function
Function Button31_onclick()
Dim table
table = $("#DataTable11").DataTable()
$(table.rows().nodes()).removeClass("highlight")
$(table.cells().nodes()).removeClass("highlight")
$(table.column(2).nodes()).addClass("highlight")
End Function
Function Button41_onclick()
Dim table
table = $("#DataTable11").DataTable()
$(table.rows().nodes()).removeClass("highlight")
$(table.cells().nodes()).removeClass("highlight")
$(table.row(2).nodes()).addClass("highlight")
End Function
Function Fliptoggle11_onchange()
DataTable11.settings.ordering = Fliptoggle11.value
updateTable2()
End Function
Function Fliptoggle41_onchange()
DataTable11.settings.paging = Fliptoggle41.value
updateTable2()
End Function
Function Fliptoggle51_onchange()
DataTable11.settings.searching = Fliptoggle51.value
updateTable2()
End Function