c# - Why won't datatables plug-in not work for my ASP.NET MVC 4? -
i want enable infinite scrolling. have installed datatables plug-in using nuget on visual studio 2012 project. standard model, view, , controller project.
- ran "install-package jquery.datatables" in package manager console
- added < thead > , < tbody > view
- added script view
- took @ similar issues on stackoverflow, no success
problem coding demo teach myself infinite scrolling, in preparations serious project. have 30 names. should want show first 10 names , can infinite scroll show everyone. project compiles no errors. however, when table. see no change being rendered @ datatables plugin. displays 30 names, before.
model-view
public class ismodel { //[scaffoldcolumn(false)] public int id { get; set; } public string name { get; set; } public int age { get; set; } // array list of bools displaying achievement images? if true, display image on list, else don't display (alt text 1.g) //public bool[] achieve { get; set; } }
controller action
public actionresult index() { return view(db.ismodel.tolist()); //return view(); }
layout file
@styles.render("~/content/css") @scripts.render("~/bundles/jquery") @scripts.render("~/scripts/jquery.datatables.js") @scripts.render("~/bundles/modernizr")
please note layout autogenerated msvs2012. has standard home , buttons. autogenerated login features.
view
@model ienumerable<isdemo.models.ismodel> @{ viewbag.title = "index"; } <h2>index</h2> <p> @html.actionlink("create new", "create") </p> <table id = "demotable"> <thead> <tr> <th> @html.displaynamefor(model => model.name) </th> <th> @html.displaynamefor(model => model.age) </th> <th></th> </tr> </thead> <tbody> @foreach (var item in model) { <tr> <td> @html.displayfor(modelitem => item.name) </td> <td> @html.displayfor(modelitem => item.age) </td> <td> @html.actionlink("edit", "edit", new { id=item.id }) | @html.actionlink("details", "details", new { id=item.id }) | @html.actionlink("delete", "delete", new { id=item.id }) </td> </tr> } </tbody> </table> @section scripts{ <script type="text/javascript"> $(document).ready(function(){ $('#demotable').datatable({ "bscrollinfinite": true, "bscrollcollapse": true, "sscrolly": "200px" }); }); </script> }
first try decrease value "sscrolly" parameter less value , if helps should need find technique adjust "sscrolly" value parent element's height.
Comments
Post a Comment