I have a string returned from a function which is in JSON format.
Below is the text structure
[{"ID":89,"COMPLAINTTYPE":"Motherboard complaint","CTYPE_ABS":"Motherboardcomplaint"},{"ID":90,"COMPLAINTTYPE":"CMOS batter not working","CTYPE_ABS":"CMOSbatternotworking"},{"ID":91,"COMPLAINTTYPE":"Memory damaged","CTYPE_ABS":"Memorydamaged"},{"ID":92,"COMPLAINTTYPE":"SMPS damaged","CTYPE_ABS":"SMPSdamaged"}]
which consists three fields and values from database ID, COMPLAINTTYPE, CTYPE_ABS
How can I use this as data for a JQUERY Datatable?
I am new to JQUERY. I want to replace Datagrid with JQUERY Datatable
Kindly help
What I have tried:
I have created the JSON format form my VB.net Function
Public Function generatetabledata(sqlstr As String) As String
Dim dt As New DataTable()
Using con As New SqlConnection(IDvar.Constr)
Using cmd As New SqlCommand(sqlstr, con)
Dim jsondata As String
con.Open()
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
Dim serializer As New System.Web.Script.Serialization.JavaScriptSerializer()
Dim rows As New List(Of Dictionary(Of String, Object))()
Dim row As Dictionary(Of String, Object)
For Each dr As DataRow In dt.Rows
row = New Dictionary(Of String, Object)()
For Each col As DataColumn In dt.Columns
row.Add(col.ColumnName, dr(col))
Next
rows.Add(row)
Next
jsondata = (serializer.Serialize(rows))
Return jsondata
con.Close()
cmd.Dispose()
dt.Clear()
End Using
End Using
End Function
I used below code to call Datatable
<script>
$(document).ready(function () {
$('#datatable-tabletools').DataTable({
"ajax": {
"url": "datacall/GetCata",
"dataSrc": "",
"data": '<%= Session("ctypedata")%>'
},
"columns": [
{ "data": "ID" },
{ "data": "COMPLAINTTYPE" },
{ "data": "CTYPE_ABS" } ]
});
});
</script>
<table class="table table-bordered table-striped mb-none" id="datatable-tabletools" data-swf-path="assets/vendor/jquery-datatables/extras/TableTools/swf/copy_csv_xls_pdf.swf">
<thead>
<tr>
<th>ID</th>
<th>Complaint</th>
<th>Ctype</th>
</tr>
</thead>
</table>
the JSON string is stored in
Session("ctypedata")