$(
function
() {
$(
'#tblAppendGrid'
).appendGrid({
columns: [
{ name:
'Album'
, display:
'Album'
},
{ name:
'Artist'
, display:
'Artist'
, ctrlAttr: { title:
'Please fill in the Artist name!!'
}, uiTooltip: { show:
true
} },
{ name:
'Year'
, display:
'Year'
},
{ name:
'Duration'
, display:
'Total Duration'
, type:
'custom'
, value:
'0:00:00'
,
customBuilder:
function
(parent, idPrefix, name, uniqueIndex) {
var
ctrlId = idPrefix +
'_'
+ name +
'_'
+ uniqueIndex;
var
ctrl = document.createElement(
'span'
);
$(ctrl).attr({ id: ctrlId, name: ctrlId }).appendTo(parent);
$(
'<input/>'
, { type:
'text'
, maxLength: 1, id: ctrlId +
'_Hour'
}).css(
'width'
,
'20px'
).appendTo(ctrl).spinner({ max: 9, min: 0 });
$(
'<input/>'
, { type:
'text'
, maxLength: 2, id: ctrlId +
'_Minute'
}).css(
'width'
,
'20px'
).appendTo(ctrl).spinner({ max: 59, min: 0 });
$(
'<input/>'
, { type:
'text'
, maxLength: 2, id: ctrlId +
'_Second'
}).css(
'width'
,
'20px'
).appendTo(ctrl).spinner({ max: 59, min: 0 });
return
ctrl;
},
customGetter:
function
(idPrefix, name, uniqueIndex) {
var
ctrlId = idPrefix +
'_'
+ name +
'_'
+ uniqueIndex;
var
hour = $(
'#'
+ ctrlId +
'_Hour'
).spinner(
'value'
);
var
minute = $(
'#'
+ ctrlId +
'_Minute'
).spinner(
'value'
);
var
second = $(
'#'
+ ctrlId +
'_Second'
).spinner(
'value'
);
return
hour +
':'
+ (minute < 10 ?
'0'
+ minute : minute) +
':'
+ (second < 10 ?
'0'
+ second : second);
},
customSetter:
function
(idPrefix, name, uniqueIndex, value) {
var
ctrlId = idPrefix +
'_'
+ name +
'_'
+ uniqueIndex;
var
sep =
null
;
if
(value !=
null
&& -1 != value.search(/^[0-9]:[0-9]{1,2}:[0-9]{1,2}$/)) {
sep = value.split(
':'
);
}
$(
'#'
+ ctrlId +
'_Hour'
).spinner(
'value'
, sep ==
null
? 0 : sep[0]);
$(
'#'
+ ctrlId +
'_Minute'
).spinner(
'value'
, sep ==
null
? 0 : sep[1]);
$(
'#'
+ ctrlId +
'_Second'
).spinner(
'value'
, sep ==
null
? 0 : sep[2]);
}
}
]
});
});