axisj icon indicating copy to clipboard operation
axisj copied to clipboard

AXGrid내 formatter "money"로 주는 경우

Open chobise opened this issue 9 years ago • 3 comments

안녕하세요. 바쁘신데 수고가 많으십니다.

예를들어 쿼리에서>>>> SELECT NAME , AGE1 , AGE2 , AGE3 FROM MYTABLE;

위 데이터를 그리드에 바인딩할 경우

{ key: "NAME", label: "NAME", width: "100", align: "center", formatter: "dec" }, { key: "AGE1", label: "AGE1", width: "150", align: "left", formatter: "dec" }, { key: "AGE2", label: "AGE1", width: "150", align: "left", formatter: "dec" }, { key: "AGE3", label: "AGE1", width: "150", align: "left", formatter: "dec" }, { key: "AGE4", label: "AGE4", width: "100", align: "center", formatter: "dec" }, { key: "AGE5", label: "AGE5", width: "100", align: "center", formatter: "money" }

AGE4 의 컬럼에는 불러오는 값이 없어 공백으로 나오지만(formater dec) AGE5의 경우에는 formatter가 money이기 때문에 0으로 나옵니다. 값이 없는 것과 값이 0인것은 다르다고 생각되는데요.

이런 경우는 어떻게 처리해야하는지 궁금합니다. 값이 있는 경우 money 타입이 적용되고 없는 경우 그냥 공백으로 나오게 처리하고 싶습니다.

답변 부탁드립니다. 감사합니다.

chobise avatar Oct 21 '16 05:10 chobise

formatter: function(){
   if(this.item.AGE5){
      return this.item.AGE5.money()
   }else{
      return ""
   }
}


lhslive avatar Oct 21 '16 06:10 lhslive

답변 감사합니다. (다른 분들도 보시면 불쾌해 하실 것 같아 댓글 정정합니다. 죄송합니다. 주의하겠습니다.)

chobise avatar Oct 21 '16 07:10 chobise

   if(this.item.AGE5){
      return this.item.AGE5.money()
   }else{
      return ""
   }

여기서 if 에 안들어가게 하면 되지 않을까요. 오픈소스 프로젝트에 요구하는 투로 질문 하시는건 힘들게 시간내어 답변 해주신 분에게 예의가 아닙니다. 주의 부탁드립니다.

if(typeof this.item.AGE5 !== "undefined" && typeof this.item.AGE5 !== "")

과 같은 식으로 데이터 체크를 하시면 해결될 것 같습니다. 자바스크립트의 형 체크하는 구문은 구글링 하면 엄청나게 많은 자료를 찾을 수 있습니다.

thomasJang avatar Oct 21 '16 07:10 thomasJang