[jquery] grid combobox selected set
그리드 안에 콤보박스가 있고 콤보박스의 선택 값을 추출하여 DB에 insert 및 update, delete를 할 경우 그리드 안의 선택된 콤보박스의 값이 제대로 추출되는 않는 경우들이 있다. 이러한 경우는 화면이 최초 로드될 때 그리드의 콤보박스에 값을 셋팅하는 과정에서 val()로 값을 셋팅하여 생기는 문제이다.
최초 콤보박스에 값을 매핑할 경우 val()만 사용하지 말고 아래와 같이 attr("selected", "selected")를 사용하여 설정해주면 됩니다.
$selectedTr = $("#gvList > tbody > tr:last").find("td Select");
$selectedTr.each(function () {
var id = $(this).attr("id");
if (id == "ddlYear"){
$(this).val(Year);
$(this).find("option").each(function() {
if($(this).val() == Year) {
$(this).attr("selected", "selected");
}
});
}
if (id == "ddlUserId"){
$(this).val(UserId);
$(this).find("option").each(function() {
if($(this).val() == UserId) {
$(this).attr("selected", "selected");
}
});
}
if (id == "ddlType1"){
$(this).val(Type1);
$(this).find("option").each(function() {
if($(this).val() == Type1) {
$(this).attr("selected", "selected");
}
});
}
if (id == "ddlType2"){
$(this).val(Type2);
$(this).find("option").each(function() {
if($(this).val() == Type2) {
$(this).attr("selected", "selected");
}
});
}
$(this).hide();
});
이상으로 [jquery] grid combobox selected set에 관해서 알아보았습니다.
오늘도 행복한 하루 되세요~^^
하여 오늘은 [jquery] grid combobox selected set에 관해서 알아보겠습니다.
최초 콤보박스에 값을 매핑할 경우 val()만 사용하지 말고 아래와 같이 attr("selected", "selected")를 사용하여 설정해주면 됩니다.
$selectedTr = $("#gvList > tbody > tr:last").find("td Select");
$selectedTr.each(function () {
var id = $(this).attr("id");
if (id == "ddlYear"){
$(this).val(Year);
$(this).find("option").each(function() {
if($(this).val() == Year) {
$(this).attr("selected", "selected");
}
});
}
if (id == "ddlUserId"){
$(this).val(UserId);
$(this).find("option").each(function() {
if($(this).val() == UserId) {
$(this).attr("selected", "selected");
}
});
}
if (id == "ddlType1"){
$(this).val(Type1);
$(this).find("option").each(function() {
if($(this).val() == Type1) {
$(this).attr("selected", "selected");
}
});
}
if (id == "ddlType2"){
$(this).val(Type2);
$(this).find("option").each(function() {
if($(this).val() == Type2) {
$(this).attr("selected", "selected");
}
});
}
$(this).hide();
});
이상으로 [jquery] grid combobox selected set에 관해서 알아보았습니다.
오늘도 행복한 하루 되세요~^^
댓글
댓글 쓰기