search by clicking on grouped field
search by clicking on grouped field
silens
Posts: 101Questions: 40Answers: 0
I have a table grouping by a field and I would like that when clicking on the group, I will search for that value
"initComplete": function (settings, json) {
var api = this.api();
api.$('td').not(":nth-child(3), :nth-child(6), :nth-child(7), :nth-child(8)").click(function () {
api.search(this.innerHTML).draw();
});
},
"drawCallback": function (settings) {
var api = this.api();
var rows = api.rows({
page: 'current'
}).nodes();
var last = null;
api.column(0, {
page: 'current'
}).data().each(function (group, i) {
if (last !== group) {
$(rows).eq(i).before('<tr class="group"><td colspan="6"><b>' + group + '</b></td></tr>');
last = group;
}
});
},
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Your code seems to work if you click on a row within the group. Are you wanting to search by clicking on the row created with the group title?
If so maybe this example will help. I just added a data attribute to the row.
http://live.datatables.net/tovohoca/1/edit
Kevin
Thanks for answering, the grouped field search gives the following error, if I search for row without grouping if it does well.
```
Uncaught TypeError: api.search(...).draw is not a function
```
Hello, now he does it well, but he only does it well once, the following times he does not do it and he does not give error either.
this is my function:
I used the wrong event selector. This appears to work:
http://live.datatables.net/tovohoca/4/edit
$('table').on('click', '.group', function () {
Kevin
Perfecto. Muchisimas gracias