Material-Table replace checkboxes with radio buttons - reactjs

I'm using material-table to show some data, now I want to select one row at the time to pass the row's data to another component, so being able to select multiple rows at the time isn't what I'm looking for and the main suggestion is to go for a radio button. So is there a way to replace the checkbox on the table with radio buttons or make the selection option to only allow one row to be selected at the time?

According to documentation your hands are tied. But, this might work:
Add selectedRow key to the component which uses MaterialTable
Create some method or function e.g. handleSelection and pass it to onSelectionChange prop. Argument to this func is an array which handleSelection returns
When user select some row, set selectedRow to that row object
If user click on "slelect all" checkbox (top left) - show notification that action is not supported. If there is no way to unselect all checkboxes programatically - unmount and than mount MaterialTable (to reset checkboxes)
If one row is already selected, than another one get selected (which makes two selected rows) - repeat step "4"
I know this is a bit complicated, but it's a best I could think of at the moment
n.b. Another thing you can do (to force users to select only one row) is to hide table on multiple selection and show message about what they can do. Message could be closable. When message get closed fresh table could appear (mount aggain).
Update
Just have found another option that might work for you. Take a look at this page at the "Simple Action Example". There you have buttons instead of checkboxes. I am starting to think that:
options={{
selection: true
}}
is not the right option for you.

Related

How to access click event of option in React dual list box?

I am using react-dual-listbox. Here I am able to select the columns and deselect and use the selected values. But, I want to access the selected option in selected items on click of that particular item.
Ex: if 2 options are selected. If i click on second one, It should give me the value and index of the selected option. I saw something to use selectedRef for that purpose, But I am new to React.
Could anyone please help me out.
<DualListBox
canFilter
preserveSelectOrder
options={this.state.availableColumns}
selected={selectedColumns}
onClick={this.selectedRef}
onChange={this.onColumnSelected}
/>

Antd table expand row and place textarea inside

I am trying to implement row editing with Antd where when I click on the Edit link the row expands and has a textarea inside the user can type into. I haven't been able to figure out how to trigger row expansion (didn't see any onclick event handlers on the + sign) nor how to get access to the expanded row element to slide a form field in there in a non hacky way.
This is the current code - https://gist.github.com/llevar/8f9a68bcc15ab0e37defb14a5126c5ad. The goal is to have the column "Configuration" with JSON in it end up in a text area upon clicking Edit.
Thanks in advance.
Did you try
onExpandedRowsChange props and onExpand they give you access to the expanded row callback and expanded row change.
edit:
I haven't try this, but I think you should be able to programatically expand rows with expandedRowKeys and state. and use the expandedRowRender to conditionally render "view mode" and "edit mode(text area)", also you can add a save button to save the textarea values and turn it back to "view mode"
onExpand is trigger when you press the + icon (or expand the row via rowClick)

Select Unselect logic in Salesforce

I have a requirement, where there is a checkbox on UI when I select it the first time it gets selected when I click it again it is deselected.
So in logic, I am adding the selected parameter to a set, and if it is already present I remove it for deselecting the parameter.
But this approach is not working when I have to count how many I have total, it gives incorrect values.
I have to implement select multiple and deselect multiple in a web page. Can anyone help me with this
Do you have a wrapper? Have a select all/deselect all command link, that command link will call an action which will select/deselect all of the records, then just rerender the table..

Apex radio button check from controller

I have a scenario and i ma getting no where:
I am having 20 record and i m using pagination via standartcontroller and my page size is 1.
one by one record are displayed on the screen and i am having a list or radio button to select options.
When user select a radio button i am getting its value and fill a map with record,value for some processing.
What i want to do is that when a user hits back button the option he has selected in radio button must be visible there. But its not coz every time i m filling new values in the radiobutton list so old values are not sustained.
What i want is when user hits back button he should be able to see the old radio button selected.
How can i achive this:
1.Is there any way to make a radio button list's values be checked through controller.
2.Do I need to use wrapperclass to do this.
Help needed.! Thanks
It will be easier to put this field into object. If you don't have such field in you sObject than I would suggest to create wrapper class in your controller and display list of this wrappers instead of your native sObject.
If your radio button field is already part of the object, then there's no need for a wrapper class, but if the radio button doesn't need to be part of the object then use a wrapper class to keep the object simple.
Check out this example of a wrapper class with check boxes.
Wrapper classes don't have to be complex.

CQ5 checkboxes false

I would like to have it where i can only select one checkbox at a time and when selected show the textfield associated with the selection. At least have it where i can only select one checkbox at a time. I have setup the dialog to run a choose when statement when for the selections but only want to select one at a time.
You can use listeners to react to user actions e.g.: dynamic dialogs, however you probably want to use radios.

Resources