c# JQuery Datatable checkbox selection
c# JQuery Datatable checkbox selection
vhinchies
Posts: 6Questions: 1Answers: 0
I have a table that uses datatable and select plugins, i am able to get the data of all those selected rows and store it in hidden field to be able to access in my code behind. Now, i want CHECKED/UNCHECKED rows from my datatable based on the parameters i have.. How can i do this?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You would use the
row()
orrows()
select or deselect API's:https://datatables.net/reference/api/#select
Kevin
Is it updating the checkbox property to CHECKED or UNCHECKED?
For example i have 2 columns in my datatable:
Columns: Name, Email
Scenario: I have the array lists of names, i want to set the checkbox prop in my datatable to true if array names exists in the datatable.
Are you using the checkboxes like this Select Extension example?
https://datatables.net/extensions/select/examples/initialisation/checkbox.html
Are you wanting to set the checkbox state during table initialization - may using something like this example?
https://editor.datatables.net/examples/api/checkbox.html
Do you have example code you can post to give us more detail of how you are wanting to do this?
Kevin
Hi kthorngren, yes i am using those extensions.
i am not sure if it is in the initialization of table, i am using c# as code behind.
Here's my working code fiddle.
https://jsfiddle.net/0ovhu1Lb/
If you check my fiddle, i have a line of code where i set the value to hidden field
$("#hdnSelectedContacts").val(dataArr); This hidden field i being accessed to c# aspx code and do some manipulation.
Todo:
I want to CHECKED the check boxes from the datatable after the aspx page has been loaded with all the details.
Example: my hidden field has 2 emails (email1, email2), i will loop through this list and compare if the email is exists in the datatable then i will set the checkbox to true else false.
I think the documentation you want is here - it shows how you can use the
rows()
method that Kevin mentioned to get the checked rows (based on the selection made via the Select extension), and also how you can get the not checked rows.Allan
Hi allan, i can actually get all the selected rows the problem is how can i CHECKED the checkbox on page load?
for example in my jsfiddle provided above, how can i set it to true for the first 3 rows only of the checkboxes.
See if this updated fiddle helps:
https://jsfiddle.net/o96h2vs0/17/
It uses
filter()
andindexes()
to get the row indexes of the rows that match the email list in an array. It then uses the indexes to select the appropriate rows.Kevin
thank you kthorngren.. this solves my issue.