rmoh21
rmoh21

Reputation: 1525

Select one checkbox row only in datatables

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

Upvotes: 0

Views: 2969

Answers (4)

Damián Herrera
Damián Herrera

Reputation: 89

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

Upvotes: 0

rl99
rl99

Reputation: 501

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.

Upvotes: 1

Nagendra Rao
Nagendra Rao

Reputation: 7152

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

Upvotes: 0

tomaroo
tomaroo

Reputation: 2534

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.

Upvotes: 3

Related Questions