Search code examples
jquerybootstrap-table

How to set default uncheck all items in bootstrap table?


I follow the properties of bootstrap table from this website: [http://bootstrap-table.wenzhixin.net.cn/documentation/][1]

The table looks good, however when I load the page for the first time, the checkall items is checked. I want to uncheck it by default.

Here is my init code:

var init = function (elmId) {
    try {
        var tbId = "#table-select-controlli_" + elmId;
        var h2Id = "#header_" + elmId;
        var btnId = "#btn-aggiungi_" + elmId;
        var gridId = "#grid-box_" + elmId;
        var langcode = mifid.utils.getLangCode();
        listName = $(gridId + " input")[0].value;

        //loadData();

        $(tbId).bootstrapTable(
        {
            showRefresh: true,
            showColumns: true,
            pagination: true,
            search: true,
            pageList: [10, 25, 50, 100],
            sidePagination: 'server',
            queryParams: 'getparams',
            locale: langcode,
            columns: [{
                field: fieldName.Modulo,
                title: fieldDisplay.Modulo
            }, {
                field: fieldName.Titolo,
                title: fieldDisplay.Titolo
            }, {
                field: fieldName.AmbitoControllo,
                title: fieldDisplay.AmbitoControllo
            }],
            url: _spPageContextInfo.webAbsoluteUrl + "/_vti_bin/MIFIDServices/SelectControlliService.svc/Getdata?listName=" + encodeURIComponent(listName) + "&siteurl=" + _spPageContextInfo.webAbsoluteUrl,
            cache: false,
        });
        $(h2Id).text(listName);
        RegisterEvent(tbId);
    }
    catch (e) {
        console.log(e.message);
    }
}

Solution

  • You can uncheck all or just invert the selection. Try :

    uncheck all

    $('#your-table.id').bootstrapTable('uncheckAll');
    

    check all

    $('#your-table.id').bootstrapTable('checkAll');
    

    invert all

    $('#your-table.id').bootstrapTable('checkInvert');
    

    UPDATE

    Ok i have try with inside a document.reday():

    var tbId = '#table';
    $(tbId).bootstrapTable(
    {
        showRefresh: true,
        showColumns: true,
        pagination: true,
        search: true,
        pageList: [10, 25, 50, 100],
        sidePagination: 'server',
        queryParams: 'getparams',
        columns: [{
            field: "ddd",
            title: "ff"
        }, {
            field: "dd",
            title: "sds"
        }, {
            field: "ffff",
            title: "ffff"
        }],
        cache: false,
    });
    $(tbId).bootstrapTable('checkAll');
    

    And this work fine.