- 함수를 변수로 받아 처리해야 할 때가있다.
jqgrid 를 jqxgrid로 변경을햇었다.
jqxgrid 에서는 formatter이 없기때문에 넘어온 formatter 을 cellsrenderer 를 이용해서 값을 추출해야했다.
그런데 cellsrenderer 에는 인자가 5개가 있기때문에 그대로
col["cellsrenderer"] = colModel[j].formatter; 이렇게 넣을경우
value 가 들어가야 하는데 cellsrenderer에 첫번째 인자인 row가 들어간다.
그래서 아래처럼 처리를 했다.(나중에 전부다 바꾸긴했지만... 서비스단에서 설명값을 다시 보내주는것으로,.)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
-PurchaseDataMngMain.js
//구입자료관리 그리드 셋팅
function PurchaseGridPrint()
{
var table_id = '#purchasetable_contents';
var pagination_id = '#purchasetable_contents_pagination';
//서명,발행자,isbn,저자,발행년 을 던져야 함.
var column=[
{label:'주제명' , name:'subject_code' ,
width : 75 ,align:"center",formatter:subjectcodeFormar},
{label:'서명' , name:'title_info' , width : 414, align:"left"},
{label:'총서사항' , name:'series_area' , width : 95, align:"left"},
{label:'판사항' , name:'edit' , width : 75, align:"left"},
];
var option = {
width:getScreenSize(),
height:600,
grid_class:"purchaseGrid",
rowNum:30,
gridPaging:true,
pagingType:"grid_type",
multiselect : true,
pagination_id:pagination_id
};
// purchaseGrid = new EcoGrid(table_id,column,'',option);
purchaseGrid = new EcoGrid_jqx(table_id,column,'',option);
}
function subjectcodeFormar(row, columnfield,cellValue){
if(null == cellValue || undefined == cellValue)
{
return "";
}
var return_data = "";
// globalclassNoTypeSave = "1";
if(globalclassNoTypeSave=="1"){
return_data = getdesc("KDC대주제부호관리", cellValue);
}else if(globalclassNoTypeSave=="2"){
return_data = getdesc("DDC대주제부호관리", cellValue);
}else{
return_data = "";
}
return return_data;
}
|
cs |
1
2
3
4
5
6
7
8
9
10
11
12
|
-eco_Jqxgrid.js
//코드 formatter
if(colModel[j].formatter!= undefined && colModel[j].formatter != "currency"){
var formatter = colModel[j].formatter;
console.dir(formatter)
var cellsrenderer = function (row, columnfield, value, defaulthtml, columnproperties) { //cellsrenderer를 선언
if(col["datafield"] == columnfield ){
return formatter(value); // 필요한 변수를 다시 넣어준다.
}
}
col["cellsrenderer"] = colModel[j].formatter;
|
cs |
넝어온 함수는 배열에 담기긴 하지만 console.dir 로 열어봤을시 눈에 보이지는 않고 따로 추출할 경우에는 아래처럼 함수형태 그대로 보인다.
==> 변수로 넘어온 함수를 사용시에는
그냥 인자를 넣어주기만 하면 된다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
- 함수
function test1(value){
var a = value+1;
return a;
}
- 함수를 변수로 보냄
function fu_send()
{
var fun_data = test1; //함수를 변수에 담음
var fu_receiveData = fu_receive(fun_data ); // 변수에 담은 변수를 값을 구하기 위해 fu_receive에 인자로 보냄
//결과값을 받아
console.log(fu_receiveData ); // 4
}
- 함수를 인자로 받음 함수
function fu_receive(data)
{
return data(3);
}
|
cs |
==> test1 == fun_data == data
셋은 같은 아이들임
'개발 > javascript & jquery' 카테고리의 다른 글
날짜확인 스크립트 (0) | 2017.08.22 |
---|---|
배열의 키 (0) | 2017.05.23 |
한 화면에 여러개의 ajax를 실행해야 할 경우 (0) | 2017.05.22 |
원하는 byte만큼 글자를 잘라줌 (0) | 2017.05.02 |
가져온 달력값을 넣을땐 setData를 이용 (0) | 2017.05.01 |
댓글