Problem with grid.getSelectedId()

I have a toolbar that calls on a bunch of functions and one of the new functions that I am adding requires the string of selected rows from a multiselect grid. I can get an alert to pop up (for testing) which will display grid.getSelectedId() properly when there is only one item selected, but if I select multiple items and then call on grid.getSelectedId() I don’t get anything. I was at least expecting the comma separated string of the selected items which I can then process in my script when I pass it through AJAX.

What am I missing here?

Thanks,
-Rick

P.S. - These components are excellent! I have been creating an admin interface for a project that I am working on with them and they are just what I was looking for.

Unfortunately the issue cannot be reconstructed locally.
Please, provide any kind of sample of your code to provide an actual solution.

Here is the code that sets up the grid. There are a few events as well, but they don’t seem to be interfering.

		myGrid = myLayout.cells("b").attachGrid();
		myGrid.setImagePath("../codebase/imgs/");
		myGrid.setIconsPath("../codebase/imgs/");
		myGrid.setHeader(["","SKU","Product Name","Manufacturer","GTIN","Status","Featured","MSRP","Price"]); 
		myGrid.attachHeader("&nbsp,#text_search,#text_search,#select_filter,#text_search, ,#cspan,#cspan,#cspan");
		myGrid.setInitWidths("25,100,*,200,100,50,65,75,75");
		myGrid.setColTypes("img,edtxt,edtxt,ro,edtxt,ch,ch,edtxt,edtxt"); 
		myGrid.setColAlign("center,left,left,left,left,center,center,right,right");
		myGrid.enableMultiselect(true);
		myGrid.enableSmartRendering(true);
		myGrid.enablePreRendering(250);
		myGrid.enableAlterCss("even","uneven");
		myGrid.enableEditEvents(true,false,true);

Here is the code in the .js file for the toolbar functions.

if(id == "test"){
	list = myGrid.getSelectedRowId();
	alert(list);
	return;
}

Like I said, the alert box pops up when there is only one item selected, but when there are two it doesn’t work.

Here is the full code for the onClick Event:

		myToolbar.attachEvent("onClick",function(id){ 
			var text           = myGrid.cells(myGrid.getSelectedRowId(),2).getValue();
			var selected_prods = myGrid.getSelectedRowId();
			var clean_prods    = selected_prods.replace(/\,/g,'|');
			
			switch (id) {
				//---------------------
				case "cross-sell":
					alert("Cross-Sell: "+clean_prods);
					break;
				case "group":
					alert("Group: "+clean_prods);
					break;
				case "up-sell":
					alert("Up-Sell: "+clean_prods);
					break;
				case "bundle":
					alert("Bundle: "+clean_prods);
					break;
				//---------------------
				default:
					// Do nothing
			}
		});

I moved everything in to the main file and changed to the switch format instead of a bunch of if…then statements. Still, it does not trigger when two or more items are selected. The clean_prods variable is just a pipe delimited version of the original string so I can send it through AJAX once I get past this issue.

Thanks

The issue in your code with getting the value of a cell:

var text = mygrid.cells(mygrid.getSelectedRowId(),2).getValue();

accordingly to the cells() method:
cells(id,ind)
id - id of the row. In case of multiselect you will have the list of ids (“1,2,3,4”) but cells() method recognizes it as a single id. Please, try to split the list on the separate ids.

Thank you very much for your response. That worked perfectly. I moved anything that relied on a single id to it’s respective location and then I split the string before processing them one at a time.

:slight_smile: