The current script creates a table showing all Items from the list.

e.g. In my list there is a column named 'Category' with 'Cats' and 'Dogs'.

What I want to achieve is to FILTER and ONLY display 'Category' with 'Cats' in the HTML table.

How do i achieve this?

<SCRIPT type=text/javascript> get() ;function get() { var method = "GetListItems";                
var webURL =  $().SPServices.SPGetCurrentSite() ;                    
var list = "Core Libraries";                     
var fieldsToRead = "<ViewFields>"+"<FieldRef Name='Name' />" +"</ViewFields>";
var query = "<Query><OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy></Query>";                  

({ operation: method, async: false, webURL: webURL, listName: list,
CAMLViewFields: "<ViewFields Properties='True' />",
CAMLQuery: query, completefunc: function (xData, Status)
{ $(xData.responseXML).SPFilterNode("z:row").each(function()
{ var title = $(this).attr("ows_Title");
var update  =  $(this).attr("ows_Update");
var date  =  $(this).attr("ows_Date");

$("#myDataTable").append("<tr align='middle'>" +
"<td align='left'>"+date+"</td>" + "<td align='left'>"+update+"</td>" + "</tr>");

}); } }); };

2 Answers 2


You need to add a where condition to your CAML query.

var value = "Cats";

var query = "<Query><Where><Eq><FieldRef Name='Category' /><Value Type='Text'>" + value + "</Value></Eq></Where><OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy></Query>"; 
  • This is what i am looking for! Just 1 question, how can i do something like IF Cats is mentioned in the column, it will appear? e.g. Some columns will have 'Cats, mouse and birds' in a single field.
    – John Lee
    Dec 4, 2017 at 9:56
  • You should be able to switch out <eq> </eq> to <contains> </contains>! Dec 4, 2017 at 10:12

Make a new view and name it Cats. Go in to the List settings>Create View. Under Filter values, select Category equal to Cats. Save, et voila...

  • No, i want my displayed HTML table to filter and to display all Cats. The code should go along the lines of CAMLQuery: IF Category=Cats, display Cats.
    – John Lee
    Dec 4, 2017 at 9:11
  • Sorry I missed that. I don't know the answer, but someone else might already have posted an answer to a similar question. Try searching through some of these Answers: sharepoint.stackexchange.com/questions/tagged/caml+query
    – Tally
    Dec 4, 2017 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.