0

I want to be able to select only 1 checkbox at a time in Datatables.

In the example below, multiple rows can be selected. How can I go about only allowing one row to be selected at a time?

http://datatables.net/examples/api/form.html

2

4 Answers 4

3

You could use Radio buttons instead of checkboxes.

Example:

<input type="radio" name="fieldName" value="check1" />
<input type="radio" name="fieldName" value="check2" />
<input type="radio" name="fieldName" value="check3" />
<input type="radio" name="fieldName" value="check4" />

The "name" attribute is what groups the radio buttons together, the "value" attribute is what will differentiate them.

Sign up to request clarification or add additional context in comments.

1 Comment

could you please share an example?
1

How to select first row of the first table in an html page using jQuery? Selects one row in a given table. You could use jQuery to achieve it.

Comments

0

You should use the radio button,

<form action="path/to/form_submit_script.php" method="get">
  <input type="radio" name="red" value="Red" /> Red<br />
  <input type="radio" name="blue" value="Blue" /> Blue<br />
  <input type="radio" name="green" value="Green" /> Green<br />
  <input type="submit" value="Submit">
</form>

Here is the working example jsfiddle example

Comments

0
var _MainDataTable = $('#dataTable').DataTable();
...
$("#dataTable").on('click', 'tr', function () {
    if (_MainDataTable.$(".selected").length > 1) {
        _MainDataTable.$(".selected").removeClass('selected');
        $(this).addClass("selected");
    }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.