0

I'm currently using JS (items[i].id;) to successfully get the id of selected items in a list view, however, I would like to pull column values from the selected row(s) like "Title" etc. if possible using JS\JQuery. Is there a method for doing this by traversing the DOM instead of using the GetItemById method? Thanks!

Here is the code I'm using...

function WriteSelected() {
    var ctx = SP.ClientContext.get_current();
    var items = SP.ListOperation.Selection.getSelectedItems(ctx);
    var i;

    for (i in items)
        {
            //alert (items[i].id);
        }       
}
3
  • Please share the code snippet that you are using currently to get the item ID. Commented Apr 19, 2017 at 14:14
  • Do you mean you want to use Fields not displayed in the View ?? Commented Apr 19, 2017 at 14:59
  • No sir. The values I want are already columns in the view. My end goal is to take those values and write them to another list. Commented Apr 19, 2017 at 15:08

2 Answers 2

1

There is an object exposed by Sharepoint that you can use which is called WPQ2ListData which contains the current information of the list/grid.

Here's an example snippet to achieve what you need:

var ctx = SP.ClientContext.get_current();
var items = SP.ListOperation.Selection.getSelectedItems(ctx);
items.forEach(function(item){
   console.log('Id selected: ' + item.id);
   var listItem = WPQ2ListData.Row.filter(function(row){
        return row.ID == item.id;
    })[0];
 console.log('List Item:');
 console.log(listItem);
});
0

I am not sure why you want to use the DOM instead of the ctx object...

[].forEach.call(document.querySelectorAll("tr[class~='s4-itm-selected']")
                ,function(tr){
                               console.log(tr.getAttribute('iid').split(',')[1])
                             }
               );

Gets you the Item ID of all selected TRs

2
  • Honestly, I don't need the id's of the selected items unless I need to get the value of the columns from the GetItemById method. I just want to get the field values as efficiently as possible and run.. Commented Apr 19, 2017 at 15:41
  • Then do a .map to get the selected IDs and then a ctx.ListData.Row.filter() ? Commented Apr 19, 2017 at 15:55

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.