var datagrid;
var SBGridProperties = {};
function createGrid(){
SBGridProperties.parentid = 'SBGridArea';
SBGridProperties.id = 'datagrid';
SBGridProperties.jsonref = 'fData';
SBGridProperties.fixedrowheight = 50;
SBGridProperties.extendlastcol = 'scroll';
SBGridProperties.selectmode = 'free';
SBGridProperties.rowheader =['seq', 'update'];
SBGridProperties.columns = [
{caption : ['학원명\n(@학원)'], ref : 'academy', width : '150px', style : 'text-align:left', type : 'input', format : {type:'string', rule:'@"학원"'} },
{caption : ['설립자\n(@님)'], ref : 'name', width : '80px', style : 'text-align:center', type : 'input', format : {type:'string', rule:'@"님"'}},
{caption : ['설립일\n(yyyy/mm/dd)'], ref : 'startDay', width : '130px', style : 'text-align:center', type : 'datepicker', format : {type:'date', rule:'yyyy/mm/dd', origin : 'yyyymmdd'}, typeinfo :{displayui:true}},
{caption : ['휴대전화\n(000-0000-0000)'], ref : 'phone', width : '170px', style : 'text-align:center', type : 'input', format : {type:'string', rule:'000-0000-0000'}},
{caption : ['수강\n과목'], ref : 'curriculum',width : '60px', style : 'text-align:center', type : 'input'},
{caption : ['강의시간\n(HH:mm)'], ref : 'startTime' ,width : '110px', style : 'text-align:center', type : 'input', format : {type:'date', rule:'HH:mm', origin : 'HHmm' }},
{caption : ['수강료\n(#,###원)'], ref : 'pay', width : '100px', style : 'text-align:right', type : 'input', format : {type:'number', rule:'#,###원'}},
{caption : ['카드번호\n(customFormat)'], ref : 'cardNum', width : '130px', style : 'text-align:right', type : 'input', format : {type:'custom', callback : fnCustom}}
];
datagrid = _SBGrid.create(SBGridProperties);
$('#textValue').text('"getColumnFormat" 버튼을 클릭 해 주세요.');
};
//custom Format 설정
function fnCustom(strData){
var strFormatData = '';
if(strData.length > 0){
if(strData.length == 16){
strFormatData = strData.substring(0,4) + '-' +strData.substring(4,8) + '-' +strData.substring(8,12) + '-' + strData.substring(12,16);
}else if(strData.length == 15){
strFormatData = strData.substring(0,4) + '-' +strData.substring(4,8) + '-' +strData.substring(8,12) + '-' + strData.substring(12,15);
}else{
for(var i=0; i< strData.length; i++){
if(i > 0 && i%4 == 0){
strFormatData = strFormatData + '-';
}
strFormatData = strFormatData + strData[i];
}
}
}
return strFormatData ;
}
function getColumnFormat(){
var nCol = datagrid.getCol();
//선택된 열의 index 번호를 통해 format 값을 반환
var colFormat = datagrid.getColumnFormat(nCol);
//열 명을 찾기위해 설정
var getCaption = datagrid.getCaption('array');
if(colFormat == null){
$('#textValue').text(getCaption[0][nCol]+" 열은 적용된 포멧 값은 없습니다.");
}else{
$('#textValue').text(getCaption[0][nCol]+" 열의 반환된 포멧 값은"+JSON.stringify(colFormat)+" 입니다.");
}
};