2016-05-05 6 views
0

Ich möchte einen benutzerdefinierten Filter für Alter der Patienten erstellen (ihr Alter kann in Jahren, Monaten und Tagen sein). Der Code ist:Einfügen Textfeld in benutzerdefinierte Telerik Kendo Filter

@(Html.Kendo().Grid<RunSummary>() 
      .Name("Runs") 
      .DataSource(datasource => datasource 
       .Ajax().PageSize(25)   
       .Sort(sort => sort.Add("TimeOn").Descending())       
       .Read(read => read.Action("GetRunSummaries", "Home"))) 
      .Columns(columns => 
       { 
        columns.Bound(d => d.RunId).Title("").Width(30).Filterable(false) 
         .ClientTemplate("<input type='checkbox' unlock='true' class='primaryBox' id='#= RunId #' />").Visible(User.IsInRole("Registry Administrator")); 

        columns.Bound(c => c.UniqueId).Title(ELSORegistry.Resources.Views.Home.HomeStrings.UniqueId); 
        columns.Bound(c => c.RunNo).Title(SharedStrings.Run); 
        columns.Bound(c => c.Birthdate).Title(SharedStrings.Birthdate).Format("{0:g}").Filterable(true); 

        //columns.Bound(c => c.Age).Title(SharedStrings.Age).ClientTemplate("#= formatAge(Age)#"); 
        columns.Bound(c => c.Age).Title(SharedStrings.Age) 
         .ClientTemplate("#= formatAge(Age)#") 
         .Filterable(
          filterable => filterable 
           .UI("cityFilter") 
           .Extra(false)         
           .Operators(operators => operators 
            .ForNumber(str => str.Clear().IsEqualTo("Is equal to").IsGreaterThan("Is greater than").IsLessThan("Is less than")) 

            ) 

        ); 
        columns.Bound(c => c.TimeOn).Title(PatientStrings.TimeOn) 
         .Format("{0:g}") 
         .Filterable(true); 
        columns.Bound(c => c.TimeOff).Title(PatientStrings.TimeOff) 
         .Format("{0:g}") 
         .Filterable(true); 

        columns.Bound(c => c.isLocked).Title("Locked").ClientTemplate("#= isLocked ? 'Yes' : 'No' #"); 

        //columns.Bound(p => p.Abbreviation).Title("Mode"); 
        columns.Command(command => command.Custom("Patient").Click("selectPatient")); 
        columns.Command(command => command.Custom("Run").Click("selectRun")); 
       } 
     ) 
      .Pageable(p => p.PageSizes(new[] {10, 25, 50, 100})) 
      .Sortable() 
      .Filterable() 
      .Events(e => e.FilterMenuInit("FilterMenuFunc")) // apply x [closing box] on pop up filter box 
     ) 
</section> 

<script> 

    function cityFilter(element) { 
      element.kendoDropDownList({ 
      dataSource: [{ Name: "Days", Value: "1" }, { Name: "Months", Value: "2" }, { Name: "Years", Value: "3" }] 
      , dataTextField: "Name" 
      , dataValueField: "Value" 
         }); 
        window.setTimeout(function() { 
      element.data("kendoDropDownList").value("3"); 
     }, 1); 
    } 
</script> 

Ich muss ein Textfeld in Age Filter einfügen, um hier die Nummer (von Ages) zu setzen. Wie fügt man ein Textfeld in den benutzerdefinierten Filter ein? Vielen Dank im Voraus für jede Hilfe.

Antwort

0

Die mögliche Lösung ist:

function AgeFilter(element) { 

     element.kendoDropDownList({ 
      dataSource: [{ Name: "Days", Value: "1" }, { Name: "Months", Value: "2" }, { Name: "Years", Value: "3" }] 
      , dataTextField: "Name" 
      , dataValueField: "Value" 
     }); 

     window.setTimeout(function() { 
      element.data("kendoDropDownList").value("1"); 
     }, 1); 

und im Raster:

columns.Bound(c => c.customAge).Title(SharedStrings.Age) 
         .Filterable(
          filterable => filterable 
           .UI("AgeFilter") 
           .Extra(false) 
           .Operators(operators => operators 
            .ForString(str => str.Clear().IsEqualTo("Is equal to")) 
            ) 

         ); 

     }