Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi All.
I am triyng to get items from 2 lists ('Инструкции' and "'test')at the same time and the put them into a table on a page.
Now I have working solution for one list - 'Инструкции' (see example below).
I am using SharePoint 365.
I am not a developer. So if you can please reply with code (not just saying "you need to do this and this".
Thanks.

$(document).ready(function() {  
    loadMyItems();  
});  
  
function loadMyItems() {  
        var oDataUrl = "https://site.example/_api/Web/Lists/GetByTitle('Инструкции')/items?$select=Title,EncodedAbsUrl,Device,Related_x0020_application,Key_x0020_words&$filter=(ShowOnSearchPage eq 'Yes')&$top=5000";  
    $.ajax({  
        url: oDataUrl,  
        type: "GET",  
        dataType: "json",  
        headers: {  
            "accept": "application/json;odata=verbose"  
        },  
        success: mySuccHandler,  
        error: myErrHandler  
    });  
}  
  
function mySuccHandler(data) {  
    try {  
        var dataTableExample = $('#table_id').DataTable();  
        if (dataTableExample != 'undefined') {  
            dataTableExample.destroy();  
        }  
        dataTableExample = $('#table_id').DataTable({  
            scrollY: true,  
            "aaData": data.d.results,  
            "aoColumns": [{  
                "mData": "Title",
                         "render": function(data, type, row, meta){
            
             return data = '<a href="' + row['EncodedAbsUrl'] + '">' + data + '</a>';}

         },{  
                "mData": "Device",
"render": function( data, type, full, meta) {
if(!data){var returnText = "";}
else {var returnText = data.results;}
return returnText;	}			

         },{  
                "mData": "Related_x0020_application",
                         
         },{  
                "mData": "Key_x0020_words",
                         
           }
]  
        });  
    } catch (e) {  
        alert(e.message);  
    }  
}  
  
function myErrHandler(data, errCode, errMessage) {  
    alert("Error: " + errMessage);  
}  


What I have tried:

Unfortunatelly I couldn't find an answer in Google.
Posted
Updated 1-May-18 3:37am
Comments
Rajnarrayan Bose 22-Feb-18 10:26am    
Why donot you create a Object and add 2 List on that object and pass that single object only ..
Member 13690884 22-Feb-18 12:38pm    
Hello Rajnarrayan Bose.
As I said I am not a developer/programmer. I mean completely not a developer, even not a beginner. Everhyng what I can do is to make some minor changes in complete code.
So, I don't understand (don't know how to realize) your preposition.
If you can help, please introduce your solution in my code.
Thanks.
Rajnarrayan Bose 23-Feb-18 2:25am    
I have posted the code below , From your API end do the needful what i have done , once you pass that from your api , you will get in javascript what u have written is correct .

Only u need to change the API end code as i have posted below

public  class ObjectToPass{

 public IList<ChildClass1> Class1{ get; set; }
 public IList<ChildClass2> Class2{ get; set; }

}


Return "ObjectToPass" object in this way u will get 2 List too.
 
Share this answer
 
 
Share this answer
 
Try concatenating response for both lists, after that you can put them into a table on a page.

var response = response || [];
function loadMyItems() {  
        var oDataUrl = "https://site.example/_api/Web/Lists/GetByTitle('Инструкции')/items?$select=Title,EncodedAbsUrl,Device,Related_x0020_application,Key_x0020_words&$filter=(ShowOnSearchPage eq 'Yes')&$top=5000";  
    $.ajax({  
        url: oDataUrl,  
        type: "GET",  
        dataType: "json",  
        headers: {  
            "accept": "application/json;odata=verbose"  
        },  
        success: function (data) {
			if (data.d.results) {
				response = response.concat(data);
			}
			loadMyItems2();
		},  
        error: myErrHandler  
    });  
}
function loadMyItems2() {  
        var oDataUrl = "https://site.example/_api/Web/Lists/GetByTitle('test')/items?$select=Title,EncodedAbsUrl,Device,Related_x0020_application,Key_x0020_words&$filter=(ShowOnSearchPage eq 'Yes')&$top=5000";  
    $.ajax({  
        url: oDataUrl,  
        type: "GET",  
        dataType: "json",  
        headers: {  
            "accept": "application/json;odata=verbose"  
        },  
        success: function (data) {
			if (data.d.results) {
				response = response.concat(data);
			}
			mySuccHandler(response);
		},  
        error: myErrHandler
    });  
}
function mySuccHandler(data) {  
    try {  
        var dataTableExample = $('#table_id').DataTable();  
        if (dataTableExample != 'undefined') {  
            dataTableExample.destroy();  
        }  
        dataTableExample = $('#table_id').DataTable({  
            scrollY: true,  
            "aaData": data.d.results,  
            "aoColumns": [{  
                "mData": "Title",
                         "render": function(data, type, row, meta){
            
             return data = '<a href="' + row['EncodedAbsUrl'] + '">' + data + '</a>';}

         },{  
                "mData": "Device",
"render": function( data, type, full, meta) {
if(!data){var returnText = "";}
else {var returnText = data.results;}
return returnText;	}			

         },{  
                "mData": "Related_x0020_application",
                         
         },{  
                "mData": "Key_x0020_words",
                         
           }
]  
        });  
    } catch (e) {  
        alert(e.message);  
    }  
}  
  
function myErrHandler(data, errCode, errMessage) {  
    alert("Error: " + errMessage);  
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900