You need to sign in to do that
Don't have an account?
wixxey
Selecting only one row in datatable using checkbox
I have been using a datatable along with a checkbox in each row, I want that the user shod not select more then one row. i want to use these checkboxes as radiobox, i want to keep the multiple selection off.. my code is
<apex:pageBlockTable value="{!results}" var="assessments"> <apex:column > <apex:inputCheckbox value="{!assessments.selected}" id="selectLine1"/> </apex:column> <apex:column headervalue="Devices"> <apex:outputtext value="{!assessments.as.Device__c}" /> </apex:column> <apex:column headervalue="Manufacturer"> <apex:outputtext value="{!assessments.as.Manufacturer__c}"/> </apex:column> <apex:column headervalue="Test Name"> <apex:outputtext value="{!assessments.as.Test_Name__c}"/> </apex:column> <apex:column headervalue="Analyte"> <apex:outputtext value="{!assessments.as.Analyte__c}"/> </apex:column> <apex:column headervalue="Price in $"> <apex:outputtext value="{!assessments.as.Price__c}"/> </apex:column> </apex:pageBlockTable>
Kindly guide me whether this is possible
I have finally solved that matter by adding some jquery into my code
All Answers
I think this can be achieved in the following method:
Onclick of any of the checkbox, Disable all other checkboxes, by javascript.
There is an attribute named "disabled" for <apex:inputcheckbox/>
Please let me know if you see success with this and also let me know the failures in case of any
<apex:page standardController="account" recordSetVar="acts">
<script>
function blow(cbid,bln){
var x = cbid;
var x1 = x.split(':');
var firstpart = x1[0]+":"+x1[1]+":"+x1[2]+":"+x1[3]+":";
var secondpart = ":"+x1[5];
var mys = "{!acts}";
mys = mys.split(',');
for(var i =0; i< mys.length;i++){
if(x1[4] != i){
document.getElementById(firstpart+i+secondpart).disabled = true;
}
if(bln == false)
document.getElementById(firstpart+i+secondpart).disabled = false;
}
}
</script>
<apex:form id="frm">
<apex:pageBlock>
<apex:pageBlockTable value="{!acts}" var="a">
<apex:column >
<apex:inputCheckbox value="{!a.active__c}" onchange="blow(this.id,this.checked)" id="selectLine1"/>
</apex:column>
<apex:column value="{!a.name}" />
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
basically this is a kind of reference for you to implement according to your scenario
I have finally solved that matter by adding some jquery into my code
<apex:column >
<apex:inputCheckbox value="{!a.selected}" id="checkedone" onclick="unCheckOther(this)">
<apex:actionSupport event="onclick" action="{!getSelectedEmails}"/>
</apex:inputCheckbox>
</apex:column>
<script type="text/javascript">
function unCheckOther(cb)
{
var inputElem = document.getElementsByTagName("input");
for(var i=0; i<inputElem.length; i++)
{
if(inputElem[i].id.indexOf('checkedone') != -1)
if (inputElem[i].checked = true)
inputElem[i].checked = false;
}
cb.checked = true;
}
</script>