0

I have 2 lists where I need to fetch the data and need to display in the single HTML table. I created two functions, In one function I have ajax call which fetch the data from one list and passing that value to another function via a parameter.

In another function, i have another ajax call which fetches data from another list and I am printing in the HTML table.

When I run the code Every time, HTML table rows are shuffling, Pls can anyone help to fix the sequence of the rows?

function getpretestscore(lboardid,lboardname)
    {
                                        var siteUrl = _spPageContextInfo.webAbsoluteUrl; //current website URL
                                        var lstPreTestResp="PreTestResponses";
                                          selectFields = "$select=username,CourseId,score&$filter=username eq'"+ loginName +"' and CourseId eq '"+ lboardid+"'";
                                           $.ajax({
                                                    url: siteUrl + "/_api/web/lists/getbytitle('"+lstPreTestResp+"')/items?" + selectFields,
                                                    method: "GET",
                                                    headers: { "Accept": "application/json; odata=verbose" },
                                                     success: function (data) {
                                                     if (data.d.results.length > 0 ) 
                                                      getscore=data.d.results[0].score;
                                                    else{
                                                    getscore="--";
                                                    getposttestscore(lboardid,lboardname,getscore);}
                                                         },
                                                      error: function (data) {
                                                            alert("Error: "+ data);}
                                                   });
    }
    function getposttestscore(lboardid,lboardname,pretestscore)
    {
                                        var siteUrl = _spPageContextInfo.webAbsoluteUrl; //current website URL
                                        var lstpostTestResp="PostTestResponses";
                                          selectFields = "$select=username,CourseId,score&$filter=username eq'"+ loginName +"' and CourseId eq '"+ lboardid+"'";
                                           $.ajax({
                                                    url: siteUrl + "/_api/web/lists/getbytitle('"+lstpostTestResp+"')/items?" + selectFields,
                                                    method: "GET",
                                                    headers: { "Accept": "application/json; odata=verbose" },
                                                    success: function (data) {
                                                     if (data.d.results.length > 0 ) {
                                                      Postgetscore=data.d.results[0].score;
                                                         }
                                                    else{
                                                            Postgetscore="--";}
                                                        if(Postgetscore>=80){
                                                        tableHtml =tableHtml + "<tr class='text-left' style='height:30px'><td class='text-left' style='text-align:center'><img src='../SiteAssets/images/icon-right_new.png'></td><td class='text-left' style='text-align:center'>"+ lboardname +"</td><td class='text-left' style='text-align:center'>"+pretestscore+"</td><td class='text-left' style='text-align:center'>"+Postgetscore+"</td><td class='text-left' style='text-align:center'>" + (Postgetscore-pretestscore) +" </td></tr>";}
                                                        else if(Postgetscore<80){
                                                        tableHtml =tableHtml + "<tr class='text-left' style='height:30px'><td class='text-left' style='text-align:center'><img src='../SiteAssets/images/icon-wrong_new.png'></td><td class='text-left' style='text-align:center'>"+ lboardname +"</td><td class='text-left' style='text-align:center'>"+pretestscore+"</td><td class='text-left' style='text-align:center'>"+Postgetscore+"</td><td class='text-left' style='text-align:center'>" + (Postgetscore-pretestscore) +" </td></tr>";}
                                                        else{
                                                        tableHtml =tableHtml + "<tr class='text-left' style='height:30px'><td class='text-left' style='text-align:center'>--</td><td class='text-left' style='text-align:center'>"+ lboardname +"</td><td class='text-left' style='text-align:center'>"+pretestscore+"</td><td class='text-left' style='text-align:center'>"+Postgetscore+"</td><td class='text-left' style='text-align:center'>--</td></tr>";}
                                                      $('#dashboard_data').empty();
                                                      $('#dashboard_data').append(tableHtml + "</tbody></table>");
                                                         },
                                                      error: function (data) {
                                                            alert("Error: "+ data);}
                                                   });}
    //Few more functions are available which gets the LoginName, lboardid,lboardname
  • Well, without seeing the code it is hard to help you, so please attach it – Robert Lindgren Aug 4 '16 at 6:48
  • Hi Lindgern, Thanks for your response, Pls find the functions – Harish Aug 4 '16 at 7:33
  • Condense your code so its readable and we don't have to scroll – Danny '365CSI' Engelman Aug 4 '16 at 8:11
  • Code condensed.. Can any one pls help on this?? – Harish Aug 4 '16 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.