2017-12-04 25 views
1

Kendo Grid 사용자 지정 필터의 필터 값을 프로그래밍 방식으로 설정하려고합니다. 나는를 적용하면Kendo Grid 사용자 지정 필터 설정 필터 값 프로그래밍 방식으로

function getFieldFilter() { 
    return { 
    cell: { 
     template: function (args) { 
     var element = args.element; 

     element.kendoComboBox({ 
      dataSource: { 
      transport: { 
       read: 'api/Items' 
      } 
      }, 
      valuePrimitive: true, 
      dataTextField: 'Description', 
      dataValueField: 'Code' 
     }); 
     }, 
     showOperators: false 
    } 
    }; 
} 

: 내가 좋아하는 나의 새로운 필터 값을 적용하고있어 다음 필터

{ 
    width: '140px', 
    title: 'MyFieldTitle', 
    field: 'MyField', 
    filterable: getFieldFilter() 
} 

: 그리드 옵션에

gridOptions.dataSource.filter = [ 
    { 
     field: 'MyField', 
     operator: 'eq', 
     value: newTextValue 
    } 
]; 

내 필드 정의하는 모양 위의 그림과 같이 필터를 적용하면 열의 kendoComboBox를 클릭하고 다시 바깥 쪽을 클릭 한 후에 만 ​​작동합니다. 나의 초기 생각은 검도 그리드가 dataValueField을 적용하지 않고 단지 dataTextField으로 설정한다는 것입니다. kendo grid가 서버에 보내는 요청을 확인할 때 kendoComboBox 자체 (텍스트)에 저장된 값으로 보내지는 것이고 그 값은 아닙니다.

UI에서 kendoComboBox에서 무언가를 선택하면 모든 것이 잘 동작합니다. 하지만 위와 같이 프로그래밍 방식으로 설정하면 그렇지 않습니다.

kendoComboBox에서 내부 값을 새로 고치려면 상태를 새로 고침해야합니까, 아니면 어떻게이 문제를 해결할 수 있습니까?

편집 : 내가 할 노력하고있어 는 계통에서 kendoCombobox의 값을 받고있다.

var currentlyAppliedFilters = grid.dataSource.filter().filters; 
for (var filter of currentlyAppliedFilters) { 
    if (filter.field === 'MyField') { 
     var currentlyApplied = filter.value; 
    } 
} 

그래서 위의 코드는, 나에게 Description kendoCombobox에있는 항목의 특성,하지만 내가 실제로에게 Code 속성을 얻으려면을 줄 것입니다.

답변

0

처음에는 dataSource에 필터가 없으면 셀 필터에 옵션 레이블이 필요합니다. 그래서 첫 번째 값은 선택된 것으로 나타나지 않습니다.

예 : dojo example with optionLabel

args.element.kendoDropDownList({ 
           dataSource: args.dataSource, 
           optionLabel: "Select a color...", 
           dataTextField: "color", 
           dataValueField: "color", 
           valuePrimitive: true 
          }); 

당신은 바인딩 할 때, 기본 필터는 데이터 소스와 추가되어야 필터링 그리드를 필요로하는 경우

예 : dojo example with DataSource Filter

dataSource: { 
      data:[ { color: "#ff0000", size: 30 }, { color: "#000000", size: 33 }] , 
      filter: { field: "color", operator: "eq", value: "#ff0000" } 
        } 

희망이 도움이됩니다.

+0

필자가 다른 'dataTextField'와'dataValueField'를 사용하고 있거나 텍스트 입력으로'kendoDropDownList'를 가지고 있기 때문에 다른 경우 인 것 같습니다. –