1. 程式人生 > >easyui datagrid 單選框 效果

easyui datagrid 單選框 效果

columns: [[{
            field: 'oid',
            title: '選擇',
            width: 20,
            formatter: function(value, rowData, rowIndex){
                return '<input type="radio" name="selectRadio" id="selectRadio"' + rowIndex + '    value="' + rowData.oid + '" />';
            }
        }



onLoadSuccess: function(data){
            //載入完畢後獲取所有的checkbox遍歷
            if (data.rows.length > 0) {
                //迴圈判斷操作為新增的不能選擇
                for (var i = 0; i < data.rows.length; i++) {
                    //根據operate讓某些行不可選
                    if (data.rows[i].operate == "false") {
                        $("input[type='radio']")[i].disabled = true;
                    }
                }
            }
        },
        onClickRow: function(rowIndex, rowData){
            //載入完畢後獲取所有的checkbox遍歷
            var radio = $("input[type='radio']")[rowIndex].disabled;
            //如果當前的單選框不可選,則不讓其選中
            if (radio!= true) {
                //讓點選的行單選按鈕選中
                $("input[type='radio']")[rowIndex].checked = true;
            }
            else {
                $("input[type='radio']")[rowIndex].checked = false;
            }
        }