w2grid.toggleSearch
更新日: 2018-09-06
toggleSearch(field, [field], ...)
検索項目の表示/非表示を切り替えます。 戻り値はintegerです。
- field: string
- 検索項目のフィールド名。
説明
この関数は、検索項目内の非表示の項目の表示や、 表示中の検索項目を非表示にします。 検索項目が非表示の場合、詳細検索ポップアップや、 検索ボックスの虫眼鏡アイコンをクリックした場合等に、 該当項目が非表示になります。 トグルされた検索項目の数を返します。
グリッドを以下のように定義すると
$('#grid').w2grid({
    name : 'grid',
    columns: [
        { field: 'recid', caption: 'ID', size: '50px' },
        { field: 'lname', caption: 'Last Name', size: '30%' },
        { field: 'fname', caption: 'First Name', size: '30%' },
        { field: 'email', caption: 'Email', size: '40%' },
        { field: 'sdate', caption: 'Start Date', size: '120px' },
        { field: 'sdate', caption: 'End Date', size: '120px' }
    ],
    columns: [
        { field: 'recid', caption: 'ID', type: 'text' },
        { field: 'lname', caption: 'Last Name', type: 'text' },
        { field: 'fname', caption: 'First Name', type: 'text' }
    ],
    records: [
        { recid: 1, fname: 'John', lname: 'doe', email: 'vitali@gmail.com', sdate: '1/3/2012' },
        { recid: 2, fname: 'Stuart', lname: 'Motzart', email: 'jdoe@gmail.com', sdate: '2/4/2012' },
        { recid: 3, fname: 'Jin', lname: 'Franson', email: '--', sdate: '4/23/2012' },
        { recid: 4, fname: 'Susan', lname: 'Ottie', email: 'jdoe@gmail.com', sdate: '5/3/2012' },
        { recid: 5, fname: 'Kelly', lname: 'Silver', email: 'jdoe@gmail.com', sdate: '4/3/2012' },
        { recid: 6, fname: 'Francis', lname: 'Gatos', email: 'vitali@gmail.com', sdate: '2/5/2012' }
    ]
});以下のように指定します。
w2ui['grid'].toggleSearch('recid', 'fname');デモ
グリッドをクリックするたびに、検索項目の"ID"と"First Name"を表示/非表示を切り替えます。
JavaScript
$('#grid').w2grid({
    name    : 'mygrid',
    url     : '../json/data.json',
    columns : [
        { field: 'recid', caption: 'ID', size: '50px' },
        { field: 'lname', caption: 'Last Name', size: '30%' },
        { field: 'fname', caption: 'First Name', size: '30%' },
        { field: 'email', caption: 'Email', size: '40%' },
        { field: 'sdate', caption: 'Start Date', size: '120px' },
        { field: 'sdate', caption: 'End Date', size: '120px' }
    ],
    searches: [
        { field: 'recid', caption: 'ID', type: 'int' },
        { field: 'fname', caption: 'First Name', type: 'text' },
        { field: 'lname', caption: 'Last Name', type: 'text' }
    ]
});
w2ui['mygrid'].on('click', function(event) {
    w2ui['mygrid'].toggleSearch('recid', 'fname');
});
© 2017.  .
.
Code licensed under theMIT License. Documentation licensed underCC BY 3.0.
このコンテンツはvitmalinaによるw2ui.gridドキュメントを翻訳/改変したものです。