I have a json data coming from backend and it get fetched into html table when user search any query

I have a json data coming from backend and it get fetched into html table when user search any query

jayvermajayverma Posts: 1Questions: 1Answers: 0

issue - when user tries to get the result for different search string . it do not show the result as per latest query.
Also i have used "destroy" : true but not able to fix it.

Thanks in advance

============================================================================

fetchButton.addEventListener('click', function(event) {
input_value = datasetName.value;
$.getJSON(getWebAppBackendUrl('/first_api_call?input_value='+input_value), function(data) {
console.log('Received data from backend', data)
//output_.innerHTML = "Backend Reply : <br>";
//output_.appendChild(document.createTextNode(JSON.stringify(data['data'][0]['result']['query_result'], null, 2)));
myParentObj = data['data'][0];
query_id = myParentObj.query_id;
query = myParentObj.result.query;
no_of_docs = myParentObj.result.statistics['no of documents containing the exact query'];
myarr = data['data'][0]['result']['query_result'];
alert('data has stored in myarr');
//document.write(myjson)
for(var i = 0; i < myarr.length; i++){
alert('outer for loop executed');
docer = myarr[i].doc;
part_number = myarr[i].PN;
count = myarr[i].count;
type = myarr[i].Type;
page_sent_dtl_arry = myarr[i].page_sentence_details;
//document.write(page_sent_dtl_arry);
len = page_sent_dtl_arry.length;
//console.log(len);
for(var j=0; j<len;j++){
alert('inner for loop executed');
pg = page_sent_dtl_arry[j].page_no;
sent = page_sent_dtl_arry[j].sentences;
sent = sent[0];
$('#tbodydata').append("<tr>"+
"<td>"+query_id+"</td>"+
"<td>"+query+"</td>"+
"<td>"+no_of_docs+"</td>"+
"<td>"+docer+"</td>"+
"<td>"+part_number+"</td>"+
"<td>"+count+"</td>"+
"<td>"+type+"</td>"+
"<td>"+pg+"</td>"+
"<td>"+sent+"</td>"
+"</tr>"
);

}; //inner loop closed

}; // outer loop closed
$(document).ready(function(){
$('#mytablenew').DataTable({
//"bServerSide": true,
//alert('just before destroy')
"destroy": true
//alert('just after destroy');

   // buttons: ['copy','csv', 'excel']

    });
    });     

}); //getJson body closed

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

Sign In or Register to comment.