2015-02-10 135 views
1

嗯,我在ASP.NET MVC應用程序中使用Kendo UI網格。我的目標是去除的過濾嘴的一些項目當一個特定的JavaScript事件是由另一過濾器B.Kendo UI Grid ASP.NET MVC - UI怪異

所以,我已經開始與設置自定義UI我列的CategoryId提出:

@(Html.Kendo().Grid(Model.Items) 
        .Name("grid") 
        .Columns(columns => 
        { 
    .... 
    columns.ForeignKey(p => p.CategoryId, Model.Categories, "CategoryId", "CategoryName") 
    .Filterable(filterable => filterable.UI("categoryFilter"))); 
    .... 
} 

某處以上之前,我定義我的JavaScript UI功能:

function categoryFilter(element) { 
    console.log('Kendo UI will never run me '); // Unreachable part 
    element.kendoAutoComplete({ 
     dataSource: customDataSource, 
     optionLabel: "--Select Value--" 
    }); 
} 

劍道電網從來沒有通話功能categoryFilter,仍然是一個錯誤是由劍道提出時,我嘗試使用無效的函數名稱,例如:

.... 
// Kendo raise an error here 
.Filterable(filterable => filterable.UI("functionWitchDoesntExist"))); 
.... 

問題:我錯過了什麼讓我的UI過濾器工作?

我的問題的另一種解決方案是,如果我可以通過jQuery獲取現有的過濾器。喜歡的東西:

$('#grid').find('.kendoautocompletefilter').options('.....') 
+0

好像自定義過濾器不適合對外關鍵列。請與telerik團隊覈對。 – Andrea 2015-02-10 18:13:22

+0

你可能想嘗試把'categoryFilter' JS函數放在你的網格定義之上。不知道這是否是問題,只是一個想法。 – 2015-02-11 15:39:05

+0

@ mmillican56:謝謝您的評論。實際上它已經超出了網格定義。 – Ksv3n 2015-02-11 16:37:03

回答

0

您可以使用數據綁定事件:

Events(Function(o) o.DataBound("YourFunction") 

,並添加或刪除的javascript過濾:

YourFunction function (yourValues) 
{ 
    var filter = { 
     logic: "or", 
     filters: [] 
    }; 

    filter.filters.push(
     { field: "Status", operator: "contains", value: yourValues }, 
     { field: "PriorityLevelDisplayText", operator: "or", value: yourValues}, 

    ); 

    myGrid.dataSource.filter([filter]); 
};