How Do I use SelectRowByIID

Hello!

I am trying to programmatically select a single row in a sharepoint list.

As far as I know and tried the next function will select the specific item in the list by it's index

var i = 0; // a number for selecting the right index.

SelectRowByIndex(ctx, i, true);

However, I want to do exactly the same thing. the problem is that I don't need to use the index - but I do need to use the Item id (assuming that I know the ID).

I saw that the SelectRowByIID command - but I don't know how to use it (What it's syntax?).

I will very appreciate your help.

Thanks in advance :)

July 30th, 2015 12:42pm

You can use JSOM or REST as an example,

function GetDetailInfo(itemID, callback) {
  $.ajax({
    url: "/_api/Web/Lists/getByTitle('ListName')/Items/getById(" + itemID + ")", 
    headers: {
      Accept: "application/json; odata=verbose"
     }
   }).success(callback);
}


//You can it like
GetDetailInfo(1, function(item) {
   // work with item
});

Free Windows Admin Tool Kit Click here and download it now
July 30th, 2015 1:05pm

Thank You for your quick answer.!!! very helpful.

since I uploaded my question i came with an idea:

 

var arr = document.getElementsByClassName('cb');
var theind = findInArray(arr);
function findInArray(arr) {
  for (var i = 0; i < arr.length; i++) {
    var el = arr[i];
    if (el.id == thecb.id)
        return i;
  }

};
theind;

SelectRowByIndex(ctx, theind, true);

***

creating an element in array that suits the list items - get it's place (by its id) in an array of the elements with the same class name. and then I will use this index with the list items as it is in the code above/

Thank you for the new way!

July 30th, 2015 1:18pm

Use below function if you need to iterate in a view easily.

function applyJS() 
{ 
    var theTDs = document.querySelectorAll(".ms-vb-title a");   
    var i=0;   
    var TDContent = " ";   
    var indexFinder = ""; 
    var tLength = theTDs.length; 
    while (i < theTDs.length)  
    {       
        try  
        {          
            theTDs[i].setAttribute("target" , "_blank" );     
			theTDs[i].removeAttribute("onclick")	
        }   
        catch(err){}   
        i=i+1;   
    };   
} 

_spBodyOnLoadFunctionNames.push("applyJS"); 

Free Windows Admin Tool Kit Click here and download it now
July 30th, 2015 1:28pm

Hi,

We can use the following code to achieve your requirement, please add the code into a content editor web part.

<script src="http://code.jquery.com/jquery-1.11.3.min.js" type="text/javascript"></script>
<script type="text/javascript">
	$(document).ready(function(){
	    var itemId=2;// list item id
	    var iid=$(".ms-listviewtable tr[id$=',"+itemId+",0']").attr("iid");
	    SelectRowByIID(iid,true);
	});
</script>

Best Regards

August 3rd, 2015 11:48pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics