2013-06-24 72 views
1

我有這樣的網格過濾劍道UI電網與申請對象類型

$("#address-grid").kendoGrid({ 
    dataSource: { 
     transport: { 
      read: { 
       url: "operations/get_sales_reps_addresses.php?salesRepsId=" + salesRepsId, 
       type: "GET" 
      }, 
      update: { 
       url: "operations/edit_address.php?salesRepsId=" + salesRepsId, 
       type: "POST", 
       complete: function (e) { 
        $("#address-grid").data("kendoGrid").dataSource.read(); 
       } 
      }, 
      destroy: { 
       url: "operations/delete_address.php", 
       type: "POST", 
       complete: function (e) { 
        $("address-grid").data("kendoGrid").dataSource.read(); 
       } 
      }, 
      create: { 
       url: "operations/add_address.php?salesRepsId=" + salesRepsId, 
       type: "POST", 
       complete: function (e) { 
        $("#address-grid").data("kendoGrid").dataSource.read(); 
       } 
      }, 
     }, 
     schema: { 
      data: "data", 
      total: "data.length", //total amount of records 
      model: { 
       id: "SalesRepId", 
       fields: { 
        AddressType: { 
         defaultValue: { 
          AddressTypeid: 1, 
          AddressTypeName: "Work" 
         } 
        }, 
        Country: { 
         defaultValue: { 
          CountryId: 38, 
          CountryName: "Canada" 
         } 
        }, 
        State: { 
         defaultValue: { 
          StateId: 4223, 
          StateName: "British Colombia" 
         } 
        }, 
        City: { 
         defaultValue: { 
          CityId: 59450, 
          CityName: "Vancouver" 
         } 
        }, 
        PostalCode: { 
         type: "string" 
        }, 
        AddressText: { 
         type: "string" 
        }, 
        IsMainAddress: { 
         type: "boolean" 
        }, 
        AddressId: { 
         type: "integer" 
        } 
       } 
      } 

     }, 
     pageSize: 3, 
    }, 
    ignoreCase: true, 
    height: 250, 
    filterable: true, 
    sortable: true, 
    pageable: true, 
    reorderable: false, 
    groupable: false, 
    batch: true, 
    navigatable: true, 
    toolbar: ["create", "save", "cancel"], 
    editable: true, 
    columns: [{ 
     field: "AddressType", 
     title: "Type", 
     editor: AddressTypeDropDownEditor, 
     template: "#=AddressType.AddressTypeName#", 
    }, { 
     field: "Country", 
     title: "Country", 
     editor: CountryDropDownEditor, 
     template: "#=Country.CountryName#", 
    }, { 
     field: "State", 
     title: "State", 
     editor: StateDropDownEditor, 
     template: "#=State.StateName#", 
    }, { 
     field: "City", 
     title: "City", 
     editor: CityTypeDropDownEditor, 
     template: "#=City.CityName#", 
    }, { 
     field: "PostalCode", 
     title: "Postal Code", 
    }, { 
     field: "AddressText", 
     title: "Address", 
    }, { 
     field: "IsMainAddress", 
     title: "Main?", 
     width: 65, 
     template: function (e) { 
      if (e.IsMainAddress == true) { 
       return '<img align="center" src ="images/check-icon.png" />'; 
      } else { 
       return ''; 
      } 
     } 
     // hidden: true 

    }, { 
     command: "destroy", 
     title: "&nbsp;", 
     width: 90 
    }, 

    ] 
}); 

問題是,當我試圖通過國家或國家或城市來篩選我得到一個錯誤

TypeError: "".toLowerCase is not a function

我試着將Country的類型更改爲字符串,我使用comobox,因此值未定義。我也嘗試將類型更改爲Object,值正確顯示,但無法過濾。我得到了同樣的錯誤(toLowerCase)

我該如何解決這個問題?

我的網非常相似this example

這裏是jsFiddle。我剛剛添加了過濾器。我仍然得到以前的錯誤

我想過濾的類別,任何幫助?

回答

3

這是你如何篩選數據源Kendo dataSource , filter

因此,讓你網格的數據源,

var gridDatasource = $("#address-grid").data('kendoGrid').dataSource; 

和過濾像這樣的例子。

gridDatasource.filter({ ... }); 

如果你提供了一個工作jsFiddle,你可能會得到一個更具體的答案。

明確的答案:

您添加的過濾器,所以對於類別沒有奏效,因爲正如我所說,這是一個可觀的,而不是提交您可以過濾爲字符串。

所以你必須爲此列指定更好的過濾器,如:

field: "Category", 
title: "Category", 
width: "160px", 
editor: categoryDropDownEditor, 
template: "#=Category.CategoryName#", 
filterable: { 
    extra: false, 
    field:"Category.CategoryName", 
    operators: { 
     string: { 
      startswith: "Starts with", 
      eq: "Is equal to", 
      neq: "Is not equal to" 
     } 
    } 
} 

看到這樣的jsfiddle - >http://jsfiddle.net/blackjim/Sbb5Z/463/

+0

我加了一個工作的jsfiddle – Kamal

+0

@Kamal我添加了一個答案。一探究竟。 – AntouanK

+0

搜索工作,但你打破了類別的選擇。選擇一個類別後,類別ID顯示而不是類別名稱。如果您嘗試在該搜索之後進行搜索,則會由於整數值而失敗。請檢查它的收益! – Kamal