Tagged “mvc”
-
Buttons Extension for DataTables using MVC 5 with Bootstrap
c#
mvc
If you get errors saying that certain functions are undefined, you might be missing some scripts or have them in the wrong order.
using System.Web;
using System.Web.Optimization;
namespace YourNamespace
{
public class BundleConfig
{
// For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/lib").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/bootstrap.js",
"~/Scripts/bootbox.js",
"~/Scripts/respond.js",
"~/Scripts/jquery-ui.js"));
bundles.Add(new ScriptBundle("~/bundles/datatables").Include(
"~/Scripts/DataTables/jquery.dataTables.js",
"~/Scripts/DataTables/dataTables.bootstrap.js",
"~/Scripts/DataTables/dataTables.buttons.js",
"~/Scripts/DataTables/buttons.html5.js",
"~/Scripts/DataTables/buttons.bootstrap.js"));
// Use the development version of Modernizr to develop with and learn from. Then, when you're
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css",
"~/Content/DataTables/css/dataTables.bootstrap.css",
"~/Content/DataTables/css/buttons.bootstrap.css",
"~/Content/jquery-ui.css"));
}
}
}
And to get the buttons to show up for your table:
var table = $("#table").DataTable({
"dom": 'Bfrltip',
"buttons": ['copy', 'csv']
});
See all tags.