Default a view based on a Picklist value

Posted by ByronB on 12-Jan-2015 09:32

Hi guys

I have a 1:M Account to ThirdPartyApps, I need to exclude a column in the grid based on the Account Type. Ie if the Account Type is End User include the Reseller column and if not exclude it from view (on the list view grid). Figured the best way was to create 2 views one with reseller and one without. How can I default the selected view based on the Account Types value?

All Replies

Posted by ByronB on 12-Jan-2015 10:36

Or alternatively hide the column in the default view based on the account types value?

Posted by Godfrey Sorita on 12-Jan-2015 10:57

Hi Byron,

There is no configurable solution to your requirement but it's possible using JavaScript. Below is a code which disables similar fields on the grid control. I figured disabled property is a much neater approach although hiding it is also possible. 

<script>
function disableGridField(fieldName, gridNo) {	//enables/disables a specific grid field
	maxRowIndex = rbf_getMaxRowIndex2(gridNo); 
	for (currRow=0; currRow < maxRowIndex; currRow++) { 
		$("#rbi_grid_" +gridNo+ "_" +currRow+ "_" +fieldName).find("select").prop( "disabled", get_accountType('accountType')); 
	}
}

function get_accountType(fieldName){
	if (rbf_getPicklistCode(fieldName) == "t1") 
		return true;
	return false;
}

$(function(){
	disableGridField("department", 0);
});
</script>

NOTE: This code should be placed on a script component where grid control is located. The values in bold should be replaced based on your own naming. 

Then, add the line below to the onchange event of of your account type field.

disableGridField('department', 0);

Regards,

Godfrey

Posted by ByronB on 12-Jan-2015 11:05

Cheers Godfrey


Will try now and let you know. Appreciated


Posted by ByronB on 12-Jan-2015 11:41

Hi Godfrey

Is this code meant for user defined grids? What I am referring to is the "List of.." related records grid that uses views to filter data on the View pages. I have tried it regardless and get the following error:

"ReferenceError: rbf_getMaxRowIndex2 is not defined"

Using the following code:

<script>

function disableGridField(fieldName, gridNo) {        //enables/disables a specific grid field

maxRowIndex = rbf_getMaxRowIndex2(gridNo);

    for (currRow=0; currRow < maxRowIndex; currRow++) {

               $("#rbi_grid_" +gridNo+ "_" +currRow+ "_" +fieldName).find("select").prop( "disabled", get_accountType('accountType'));

}

}

function get_accountType(fieldName){

alert(fieldName)

     if (rbf_getPicklistCode(fieldName) == "EndUser")

          return true;

 return false;

}

$(function(){

 disableGridField("tpaResellerAccount", 0);

});

</script>

Posted by Godfrey Sorita on 12-Jan-2015 12:58

Sorry, I thought you were referring to grid controls. The code provided will not work on related list views.

I think the easiest way right now is to use 2 related list views on the page. Simply set the views and uncheck Show View Selector property. Then use JavaScript to show/hide the other related list view.

However, this will affect the performance (depending on the number of related records displayed) of the page because it will load 2 related list views. I suggest filing an enhancement request in the Ideas section of Rollbase. There should be an API to dynamically set the views in related list views.

This thread is closed