1
votes

Consider I have a list called "test" And it has 5 list items (say a, b, c, d, e) Now that I apply filter manually on the list items for a particular field Now the result is 3 list Items.

Now I want to read the fields of these 3 list items through JavaScript & do calculation on it.

I need to access the fields of the currently displayed (after filter is applied manually)

I do not want to filter it in Javascript. But I want to filter some field manually & then I want to read the displayed result. Can anyone help ?

1

1 Answers

0
votes

The following jQuery will get all the values for a column for the rows that are displayed. It works on SharePoint 2010. I left the code very verbose and with debugging statements so it's easier to understand. Keep in mind that this code will not run in IE with the console closed unless you remove the console.log and debugger lines.

$(document).ready(function() {
    var columnHeading = "Title";
    var anchor = $("a").filter(function() {
        return $(this).text() === columnHeading; //find the link that matches the text in the columnHeading variable
    });
    var th = anchor.closest("th"); //Get the parent table header
    var columnIndex = th.index(); //Get the index of the table header in the row for use on other rows
    var table = th.closest("table");
    var i;
    debugger;
    table.find("tbody").first().find("tr").not(":first").each(function() { //Loop over every row in the table EXCEPT the first row because its the table header
        i = $(this).find("td").eq(columnIndex); //find the td element at the index we determined earlier
        console.log($(i).text()); //get the text in the td. You may need to parseInt before any mathematical formulas.
    });
});

If you need clarification on anything, please let me know.