Checkboxes in columns

Checkboxes in columns

misterbeanmisterbean Posts: 4Questions: 0Answers: 0
edited September 2009 in General
Hi everybody,

I'd like to use in a table a column with its values represented by checkboxes, my data is loaded like the example from the server http://datatables.net/examples/server_side/server_side.html,

How can I display checkbox in each cell of an specific column according with this example.

Thanks in advance.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi misterbean,

    All you need to do is just return the HTML for the checkbox in the return from the server (another option would be to use fnRender to create the HTML on the client-side). DataTables will simply put whatever HTML is returned straight into the table.

    Regards,
    Allan
  • misterbeanmisterbean Posts: 4Questions: 0Answers: 0
    thanks, I try this and works, but loading the entire dataset in one request,

    Using the server-side method of the example the checkboxes lost their values after page change, big problem-

    Can you solve that ? a trick?

    Thanks again,
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi misterbean,

    The issue you face here is that the DOM is being recreated for each draw - and therefore DataTables has no idea about any page apart from the current one. Thus the state of your checkboxes are not saved.

    What you need to do, is to add an event handler to the checkboxes (on each draw - fnDrawCallback()) which will update an array with a unique ID for each checkbox (perhaps it's name would be a good option) whenever it is checked or unchecked. The fnDrawCallback() function would also run through the save array, and see if any checkboxes should be checked as they were before.

    How does that sound?

    Regards,
    Allan
  • scanregscanreg Posts: 8Questions: 0Answers: 0
    Did you try this MrBean?

    Did it work?

    Can you post the code?

    Thanks :-)
This discussion has been closed.