select rows

select rows

dahomeydahomey Posts: 3Questions: 1Answers: 0
edited July 4 in Free community support
var MonTableau = $('#results').DataTable({
        
        "ajax": {
            "url": "/json_data/data",
            "type": "GET",
            "data": function(d) {
                d.action = 'validation_devis';
                d.filters = $('#formSearch').serialize();
            }
        },
        "columns": [
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            { "orderable": false },
            null,
            { "orderable": false },
            { "orderable": false }
        ],
        "select": true, // Enable row selection
        "pageLength": 25,
        "language": {
            "url": '../../plugins/datatables/FR.json'
        },
        "order": [3, "desc"],
        "ordering": true,
        "processing": true,
        "initComplete": function(settings, json) {
            console.log('DataTables initialization complete');
        }
    });
    //list.fnDraw();
 
$(document).on('click', '.function-toggle', function(e) {
    console.log('clicked');
    var $input = $(this);
    var target = $input.data('target');

    if ($input.is(':checked')) {
        if ($input.val() == 'all') {
            MonTableau.rows().select();
        }
        $('#' + target).prop('disabled', false);
    } else {
        if ($input.val() == 'all') {
            MonTableau.rows().deselect();
        }
        if (MonTableau.rows({ selected: true }).count() <= 0) {
            $('#' + target).prop('disabled', true);
        }
    }
});

it shows me error : TypeError: MonTableau.rows(...).select is not a function
can you help please?

Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,190Questions: 26Answers: 4,925

    I placed most of your code into this test case and it works:
    https://live.datatables.net/qekoyava/1/edit

    Are you loading the select library? If not use the Download Builder to get the proper libraries for your solution.

    If you still need help please post a link to your page or a test case replicating the issue so we can help debug. Update my test case if you wish.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • dahomeydahomey Posts: 3Questions: 1Answers: 0

    Yes but the probleme that i am using ajax , when i click on "next" it calls the ajax and loeads the content that means it doesent select the rows in default

  • kthorngrenkthorngren Posts: 21,190Questions: 26Answers: 4,925
    Answer ✓

    It doesn't look like you are using server side processing, ie serverSide: true so all the rows will be at the client. I updated the test case using ajax. After clicking select all go to the next page to see the rows are selected.
    https://live.datatables.net/qekoyava/2/edit

    Yes, if you are reloading the data via ajax then those rows won't be selected. You will need to use a callback to check the select all checkbox state and use rows().select() if checked. If you need help with this the please update the test case showing us how you are reloading the data so we can offer suggestions.

    Kevin

  • dahomeydahomey Posts: 3Questions: 1Answers: 0

    okey thank you for your help
    appreciate it

Sign In or Register to comment.