Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. @(Html.Kendo().DropDownList()
  2. .Name("VesselId")
  3. .OptionLabel("Please select")
  4. .DataTextField("Name")
  5. .DataValueField("VesselId")
  6. .MinLength(3)
  7. .Filter(FilterType.Contains)
  8. .DataSource(source =>
  9. {
  10. source.Custom()
  11. .ServerFiltering(true)
  12. .ServerPaging(true)
  13. .PageSize(80)
  14. .Type("aspnetmvc-ajax")
  15. .Transport(transport =>
  16. {
  17. transport.Read("ReadVessels", "Report");
  18. })
  19. .Schema(schema =>
  20. {
  21. schema
  22. .Data("Data")
  23. .Total("Total")
  24. .Errors("Errors");
  25. });
  26. })
  27. .Virtual(v => v
  28. .ItemHeight(30)
  29. .ValueMapper("valueMapper")
  30. ))
  31.  
  32. public ActionResult VesselsValueMapper(int[] values)
  33. {
  34. var indices = new List<int>();
  35.  
  36. if (values != null && values.Any())
  37. {
  38. var index = 0;
  39.  
  40. foreach (var vessel in GetMapperVessels())
  41. {
  42. if (values.Contains(vessel.VesselId))
  43. {
  44. indices.Add(index);
  45. }
  46. index += 1;
  47. }
  48. }
  49. return Json(indices, JsonRequestBehavior.AllowGet);
  50. }
  51.  
  52. private static IEnumerable<Vessel> GetMapperVessels()
  53. {
  54. var data = new UnitOfWork();
  55. var vessels = data.VesselRepository.Get();
  56. return vessels;
  57. }
  58.  
  59. function valueMapper(options) {
  60. $.ajax({
  61. url: "@Url.Action("VesselsValueMapper", "Report")",
  62. data: convertValues(options.value),
  63. success: function (data) {
  64. console.log("Value Mapper Success")
  65. options.success(data);
  66. console.log(data);
  67. }
  68. });
  69. }
  70.  
  71. function convertValues(value) {
  72. var data = {};
  73.  
  74. value = $.isArray(value) ? value : [value];
  75.  
  76. for (var idx = 0; idx < value.length; idx++) {
  77. data["values[" + idx + "]"] = value[idx];
  78. }
  79.  
  80. return data;
  81. }
  82.  
  83. foreach (var vessel in GetMapperVessels())
  84. {
  85. if (values.Contains(vessel.VesselId))
  86. {
  87. indices.Add(index);
  88. }
  89. index += 1;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement