[ js, cssのセット ]
<!-- MultipleSelect -->
<script type="text/javascript" src="Script/jquery.multiple.select.js"></script>
<link rel='stylesheet' href='CSS/multiple-select.css' />
[ コードサンプル ]
// マルチセレクト全選択数用 //
/* この変数は、外のfunctionで使うのでload前 :/
var teuselAllCnt;
var yearselAllCnt;
var speedselAllCnt;
var lengthselAllCnt;
var widthselAllCnt;
var draughtselAllCnt;
// マルチプルセレクト //
$('#teusel, #yearsel, #speedsel, #lengthsel, #widthsel, #draughtsel').multipleSelect({
//$('#filesel, #sheetsel, #suplsel, #psnsel').multipleSelect({
allSelected: 'All',
//height: '500px'
});
// 全選択して項目数を調べる //
$('#teusel').multipleSelect('checkAll');
$('#yearsel').multipleSelect('checkAll');
$('#speedsel').multipleSelect('checkAll');
$('#lengthsel').multipleSelect('checkAll');
$('#widthsel').multipleSelect('checkAll');
$('#draughtsel').multipleSelect('checkAll');
teuselAllCnt = $('#teusel').multipleSelect('getSelects', 'value').length;
yearselAllCnt = $('#yearsel').multipleSelect('getSelects', 'value').length;
speedselAllCnt = $('#speedsel').multipleSelect('getSelects', 'value').length;
lengthselAllCnt = $('#lengthsel').multipleSelect('getSelects', 'value').length;
widthselAllCnt = $('#widthsel').multipleSelect('getSelects', 'value').length;
draughtselAllCnt = $('#draughtsel').multipleSelect('getSelects', 'value').length;
/****** ロード時は常に全選択状態なので、全選択フラグを全部オンにする */
// **** 船スペックグリッド **** //
$("#specs").jqGrid({
url: "GetVesselSpecList",
//editurl: "paramCheck",
editurl: "UpdateAVesselSpec",
mtype: 'post',
datatype: "json",
serializeGridData: function (postData) {
//postData['mindt'] = '2017-12-01';
//postData['idsql'] = 'selDailyBatchLogList';
postData['vsllk'] = vsllklast;
postData['imolk'] = imolklast;
postData['isTEUSelAll'] = '1';
postData['isYearSelAll'] = '1';
postData['isSpeedSelAll'] = '1';
postData['isLengthSelAll'] = '1';
postData['isWidthSelAll'] = '1';
postData['isDraughtSelAll'] = '1';
postData['teuselext'] = "";
postData['yearselext'] = "";
postData['speedselext'] = "";
postData['lengthselext'] = "";
postData['widthselext'] = "";
postData['draughtselext'] = "";
postData['isModOnly'] = '0';
//postData['rows'] = rownum;
return postData;
},
/*************************************************************/
// == フィルターボタンを押した時 == //
$('#fltbtn').on('click', function () {
var teuselcnt = $('#teusel').multipleSelect('getSelects', 'value').length;
var yearselcnt = $('#yearsel').multipleSelect('getSelects', 'value').length;
var speedselcnt = $('#speedsel').multipleSelect('getSelects', 'value').length;
var lengthselcnt = $('#lengthsel').multipleSelect('getSelects', 'value').length;
var widthselcnt = $('#widthsel').multipleSelect('getSelects', 'value').length;
var draughtselcnt = $('#draughtsel').multipleSelect('getSelects', 'value').length;
// グリッドの更新 //
$('#specs').jqGrid('setGridParam', {
page: 1,
serializeGridData: function (postData) {
// 単純なので、JSONにしないで配列文字列にして送信 //
/* 最後に "" を必ずつける */
postData['teuselext'] = $('#teusel').multipleSelect("getSelects", "value") + "";
postData['yearselext'] = $('#yearsel').multipleSelect("getSelects", "value") + "";
postData['speedselext'] = $('#speedsel').multipleSelect("getSelects", "value") + "";
postData['lengthselext'] = $('#lengthsel').multipleSelect("getSelects", "value") + "";
postData['widthselext'] = $('#widthsel').multipleSelect("getSelects", "value") + "";
postData['draughtselext'] = $('#draughtsel').multipleSelect("getSelects", "value") + "";
// 全選択 or Not を送信用 //
postData['isTEUSelAll'] = teuselcnt == teuselAllCnt ? '1' : '0';
postData['isYearSelAll'] = yearselcnt == yearselAllCnt ? '1' : '0';
postData['isSpeedSelAll'] = speedselcnt == speedselAllCnt ? '1' : '0';
postData['isLengthSelAll'] = lengthselcnt == lengthselAllCnt ? '1' : '0';
postData['isWidthSelAll'] = widthselcnt == widthselAllCnt ? '1' : '0';
postData['isDraughtSelAll'] = draughtselcnt == draughtselAllCnt ? '1' : '0';
postData['vsllk'] = $('#nameinp').val();
postData['imolk'] = $('#imoinp').val();
return postData;
}
}).trigger('reloadGrid');
// ローカルストレージに保存 //
// これは使ってないが、今後の為 //
if (localStorage) {
var savemap = {};
savemap['teuselext'] = $('#teusel').multipleSelect("getSelects", "value");
savemap['yearselext'] = $('#yearsel').multipleSelect("getSelects", "value");
savemap['speedselext'] = $('#speedsel').multipleSelect("getSelects", "value");
savemap['lengthselext'] = $('#lengthsel').multipleSelect("getSelects", "value");
savemap['widthselext'] = $('#widthsel').multipleSelect("getSelects", "value");
savemap['draughtselext'] = $('#draughtsel').multipleSelect("getSelects", "value");
savemap['vsllk'] = $('#nameinp').val();
savemap['imolk'] = $('#imoinp').val();
localStorage.setItem('vesselsch_specs_filter', JSON.stringify(savemap));
}
});
コメントを投稿するにはログインしてください。