♣ Tech & Biz Salon/Tech

jqgrid 라디오 버튼 적용

TasteGod 2012. 11. 19. 20:14

이런거 내 요구에 딱 맞게 쓰려면 firebug 열어서 jqgrid 만들어진 html 소스 까보면서 해야 하는데
구글링에 나와줘서 시간 벌었다.

http://stackoverflow.com/questions/8552303/jqgrid-radio-button-select-single-row

마지막 답변에 보면 코드도 적어놓았고

See the demo which demonstrate this ~ 라고... 샘플 구현 링크도 적어놓았음.

jqgrid 로 장착한 제품을 파는 업체 사이트 같은데서 올린거 같은데... 착하네...^^

근데 영업목적인가? 저런 답글 올린다고 영업이 더 되려나... 암튼^^

아래는 내 소스임. 굳이 볼 필요없고 위에 링크들 보고 하면 되는데... 그냥 적어놓겠음


    colModel :[ 

{name: 'sfstDocuId', index: 'sfstDocuId', width: 40, align: 'center', editable:false, edittype:"radio"

, sortable:false

, classes:'pss-jqgrid-pointer-nodecoration'

, formatter: function (cellValue, option) {

                    return '<input type="radio" name="radio_' + option.gid + '"  />';

                }

}, 

                               .............................

    ,beforeSelectRow: function (rowid, e) {

        var $radio = $(e.target).closest('tr').find('input[type="radio"]');

        $radio.attr('checked', 'checked');

        return true; // allow row selection

    }

.....................

$(function(){

$('#btnApply').click(function(){
fApply();
});

});

function fApply()
{
var myGridId = "grid";
var myGrid = $("#" + myGridId);
var $selRadio = $('input[name=radio_' + myGrid[0].id + ']:radio:checked'), $tr;
    if ($selRadio.length > 0) {
        $tr = $selRadio.closest('tr');
        if ($tr.length > 0) {
        opener.parent.fMaveAs($tr.attr('id'),$("#grid").getCell($tr.attr('id'), "sfstDocuNm"));        
        self.close();
        }
        else
        {
        alert("선택된 항목이 없습니다");
        return;
        }
    } else {
    alert("선택된 항목이 없습니다");
    return;
    }
}