SPCascaded dropdowns performance

Dec 21, 2011 at 8:27 PM

Hey,

I noticed that SPCascadeDropdowns was kind of slow in my environment when it was a complex dropdown.   It was calling the cascadeDropdown function whenever any property on the parent select changed. This was causing cacadeDropdowns to be called twice when a user changed the value, and subsequenly 9 webservice calls were made.  I changed it to only call cascadedropdowns when the actual selected value changes, Now I only get 4 webservice calss, and it seems a lot quicker.

I modified  function SPCascadeDropdowns as folows:

 // Input / Select hybrid 
            case "C":
                var controlId=parentSelect.Obj.attr('id');  // BIND TO THE DROPDOWN, Not The textbox
                var selector="select[ctrl='"+controlId+"']";
                $(document).delegate(selector,"change", function() {
                    cascadeDropdown(opt);
                });
              //  parentSelect.Obj.bind("propertychange", function() {
              //      cascadeDropdown(opt);
              //  });

                // Fire the change to set the allowable values
				// parentSelect.Obj.trigger("propertychange");
   				cascadeDropdown(opt);
                break;

and modified  function cascadeDropdowns as folows:

case "C":
            	// if the dropdown is in the dom, take it's value/ otherwise take the value of the textbox
            	var controlId=parentSelect.Obj.attr('id');
                var theDropdown=$("select[ctrl='"+controlId+"']");
                if (theDropdown.length===0){
	                parentSelectSelected.push(parentSelect.Obj.attr("value"));
                }
                else
                {
                	var selectedValue= theDropdown[0].options[theDropdown[0].selectedIndex].text;
                	parentSelectSelected.push(selectedValue);
                	//parentSelectSelected.push(theDropdown.attr("value"))
               	}               
                break;

 

 

Coordinator
Dec 29, 2011 at 2:54 PM

Russ:

Interesting. One of the fun things about continuing to maintain SPServices is that I get to continually fix my earlier "mistakes". I can see several efficiency gains I can get by making a few smarter choices in SPCascadeDropdowns now that you have me looking at it. I'm going to see what I can do with your suggestions here. I think that there may be some edge conditions that your approach may miss, but I'm not certain of it.

Thanks!

M.

Coordinator
Dec 29, 2011 at 3:05 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Dec 29, 2011 at 3:54 PM

Russ, Marc,

In my local fork of SPServices and the modifications I made to SPCascadingDropdowns (thread here), I also mad a change to cache List level information (I think this call is done to find out if the childcolumn is required or not) so subsequent changes to the parent column does not trigger additional calls to the server. I felt these are "safe" to cache on the browser side because they are highly unlikely to change during the life of the page.

This change also had a positive performance impact on the sites that are using this utility.

Paul

 

Coordinator
Jan 9, 2012 at 2:35 PM

In the current alpha, I've already made some changes which reduce the number of Web Services calls. I'm going to do a full pass through and see what other performance gains I can squeeze out.

I've toyed with building a true caching capability, but it would be a significant amount of work and I just haven't tackled it yet.

M.

Jan 10, 2012 at 1:50 AM
Thanks Mark,
If I can help let me know.

PS. Did/would you consider haveing a method in SPServices to get the key of the currently selected dropdown item from a lookup column? I'm starting to get this code scattered all over my site. Would be usefull if it were in spservices.... Just a thought.
Russell

On , sympmarc <notifications@codeplex.com> wrote:
>
> From: sympmarc
> In the current alpha, I've already made some changes which reduce the number of Web Services calls. I'm going to do a full pass through and see what other performance gains I can squeeze out.
>
>
> I've toyed with building a true caching capability, but it would be a significant amount of work and I just haven't tackled it yet.
>
>
> M.
>
> Read the full discussion online.
> To add a post to this discussion, reply to this email (SPServices@discussions.codeplex.com)
> To start a new discussion for this project, email SPServices@discussions.codeplex.com
> You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.
> Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com
>
>
Coordinator
Jan 10, 2012 at 4:37 AM

Russ:

I've got a private function called dropdownCtl which I could probably build on. Can you explain a little more about what you'd like the function to do? Can you show me an example of what you've got scattered about?

Thanks,
M.

Jan 10, 2012 at 2:03 PM
I just stole the code from your library, and made it a function:

function getLookupSelectedValue(displayColumnName){
var myDropDown=$("select[title='"+displayColumnName+"']")[0];
if (myDropDown=== undefined){
var myInputControl= $("input[title='"+displayColumnName+"']")[0];
var myHiddenInputControlName= $("input[title='"+displayColumnName+"']").attr("optHid");
var myHiddenInputControl= $("input[id='"+myHiddenInputControlName+"']")[0];
return myHiddenInputControl.value;
}
else{
return myDropDown.value;
}
}
I think I also have a getLookupSelectedText somewhere.


On Mon, Jan 9, 2012 at 11:37 PM, sympmarc <notifications@codeplex.com> wrote:

From: sympmarc

Russ:

I've got a private function called dropdownCtl which I could probably build on. Can you explain a little more about what you'd like the function to do? Can you show me an example of what you've got scattered about?

Thanks,
M.

Read the full discussion online.

To add a post to this discussion, reply to this email (SPServices@discussions.codeplex.com)

To start a new discussion for this project, email SPServices@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com