Get checkbox values in DataTable with pagination

1

I have a table with the DataTables plugin.

In each row of my table, I have a <input type="checkbox" /> . I have a button to enable / disable the items described in each row of the table.

Basically, I run all checkbox and send them to another method that does certain actions related to the database, an irrelevant part of the question.

My problem starts when I use table pagination because when I go through the checkbox , I can only get the values from those that are on the screen. From what I've noticed, DataTables does not give a simple hide() in the records of the other pages, it sets up tr of table as per the current page.

How can I proceed to page-independent, get all checkbox selected?

    
asked by anonymous 22.06.2015 / 20:46

2 answers

1

Resolved as follows:

var table = $('#example').DataTable({
    "bDestroy": true,
    "bSort": false
});
var Check = table.$('input:checked').serialize();

I make a restart on loading example table to be able to treat as a DataTable object, so with serialize I send all data of input:checked , data which I treat on my C # layer via Ajax .

    
03.07.2015 / 15:16
0

My suggestion in this case is to use JSF ... because it has a lot of example code and in it you can create tables with ease.

For example:

In the code snippet below, you have a ManagedBean , named bean, and this ManagedBean has a list of objects ....

With this element h:dataTable you can in this simple code snippet, set up a table with all the elements of the list, using the values present in the attributes of each object.

Detail: As in the checkbox the value is: #{item.checked} , your item object must have a boolean checked attribute with its getters and setters . So when you check / uncheck the item, its attribute will be updated with the new value. Then, when you need to know if the object was selected or not, just check this attribute.

<h:dataTable value="#{bean.list}" var="item">
    <h:column>
        <h:selectBooleanCheckbox value="#{item.checked}" />
    </h:column>
    ...
</h:dataTable>

JSF has several sites with examples of elements used, such as: Primefaces and Richfaces

For building a ManagedBean, see here to get started!

    
23.06.2015 / 19:10