2013-08-05 170 views
0

我想通過使用自定義列表在kendo UI網格中顯示不使用任何數據庫的按鈕單擊中的detials,但是我未能在網格中顯示細節,爲此目的我已經這樣做..在劍道網格中顯示值

這是我的模型

namespace KendoPratapSampleMVCApp.Models 
{ 
    public class SampleGrids 
    { 
     public List<Sample> samples; 
    } 
    public class Sample 
    { 
     public string SampleDescription { get; set; } 
     public string SampleCode {get; set;} 
     public string SampleItems { get; set; } 
    } 
} 

,這是控制器(在這裏我打電話內PostValues事件getsamples()方法(這是按鈕單擊事件))

namespace KendoPratapSampleMVCApp.Controllers 
    { 
    public class SearchResultsDisplayController : Controller 
    { 
     // 
     // GET: /SearchResultsDisplay/ 

     public ActionResult Index() 
     { 
      return View(); 
     } 
     public static IEnumerable<Sample> GetSamples() 
     { 
      List<Sample> sampleAdd = new List<Sample>(); 
      Sample s12 = new Sample(); 
      s12.SampleCode = "123se"; 
      s12.SampleDescription = "GOOD"; 
      s12.SampleItems = "newone"; 

      Sample s2 = new Sample(); 
      s2.SampleCode = "234se"; 
      s2.SampleDescription = "Average"; 
      s2.SampleItems = "oldone"; 

      sampleAdd.Add(s12); 
      sampleAdd.Add(s2);    
      return sampleAdd; 
     } 
     [HttpPost] 
     public ActionResult PostValues(Sample model) 
     { 
      return View("Index",GetSamples());    
     } 
     public ActionResult Orders_Read([DataSourceRequest]DataSourceRequest request) 
     { 
      return Json(GetSamples().ToDataSourceResult(request)); 
     }  
    } 
} 

,這是我的看法(我在這裏使用jQuery綁定)

@Scripts.Render("~/bundles/jquery")  
<script type ="text/javascript"> 
    $('#Submit1').click(function() { 
     alert('1'); // dint get this alert when I click on submit button 
     $('#grid12').data('kendoGrid').dataSource.read(); 
     // $('#grid12').css("display", "block"); 
    }); 
</script>  
@model IEnumerable<KendoPratapSampleMVCApp.Models.Sample>  
@{ 
    ViewBag.Title = "Index"; 
}  
<h2>Index</h2> 
@using (Html.BeginForm("PostValues", "SearchResultsDisplay", FormMethod.Post)) 
{ 

    <input id="Submit1" type="submit" value="SubmitValue" /> 
    @(Html.Kendo().Grid<KendoPratapSampleMVCApp.Models.Sample>()  
    .Name("grid12") 
    .Columns(columns => { 
     columns.Bound(p => p.SampleDescription).Filterable(false).Width(100); 
     columns.Bound(p => p.SampleCode).Filterable(false).Width(100); 
     columns.Bound(p => p.SampleItems).Filterable(false).Width(100); 
    }) 
    .Pageable() 
    .Sortable() 
    .Scrollable() 
    .AutoBind(false) // here I am disabling automatic binding at page load 
    .Filterable() 
    .HtmlAttributes(new { style = "height:430px;" }) 
    .DataSource(dataSource => dataSource 
     .Ajax() 
     .PageSize(20) 
     .Read(read => read.Action("Orders_Read", "SearchResultsDisplay")) 
    ) 
) 
} 

我不能夠將數據綁定,當我們提交按鈕,任何建議和任何意見將非常感激我... 許多感謝....

回答

3

,你必須在你的script這樣添加Document.ready

<script type="text/javascript"> 
    $(document).ready(function() { 
     $('#Submit1').click(function() { 
      alert('1'); // dint get this alert when I click on submit button 
      $('#grid12').data('kendoGrid').dataSource.read(); 
      // $('#grid12').css("display", "block"); 
     }); 
    }); 
</script> 

你必須改變你的按鈕式Submitbutton

<input id="Submit1" type="button" value="SubmitValue" /> 

和你的網格是完美綁定的。

+0

對不起,我已經這樣做,但它不工作....但我不捆綁網格.. –

+0

嗨pratap我只是更新我的代碼。 – Jaimin

+0

非常感謝......現在工作.. –

0

將按鈕的類型從「提交」更改爲「按鈕」,並將其稱爲JavaScript中的單擊事件。

$(document).ready(function(){ 
    $('#yourButtonId').click(function(){ 

    //write the desired logic here 

    }) 
})