使用DataTables.net的ASP.NET8——第3部分——状态保存

别再只当代码阅读器了!手把手教你用Understand的实体定位器和信息浏览器,5分钟精准定位代码逻辑 本文深入解析Understand代码分析工具的高级功能,重点介绍实体定位器和信息浏览器的实战应用。通过5分钟快速定位代码逻辑的技巧,帮助开发者从代码阅读者升级为逻辑侦探,提升大型代码库的分析效率。文章包含过滤搜索、调用链追踪等实用方法,是掌握Understand核心功能的必备指南。 阅读详情

目录

1使用jQuery DataTables.net的ASP.NET8

1.1 本系列中的文章

2 最终结果

3 客户端DataTables.net组件

4 保存状态如何运作

5 总结

6 参考资料


1使用jQuery DataTables.net的ASP.NET8

我正在评估jQuery datatable.net组件[1]在ASP.NET8项目中的使用,并创建了几个原型(概念验证)应用程序,这些应用程序将在这些文章中展示。

1.1 本系列中的文章

本系列中的文章包括: 

2 最终结果

本文的目标是创建一个概念验证应用程序,用于演示组件状态保存 DataTables.net。让我们介绍一下这篇文章的结果。在此屏幕上,您会看到处于特定“state”的示例应用程序,即应用了过滤器“mark”,并按“Family name”降序排序。

用户经常要求,当他们离开页面然后返回时,他们处于与离开时相同的状态。如本文所示,您可以在此应用程序中导航离开并返回,并且DataTables组件将处于与您离开时相同的状态。

本文的主题是展示如何实现它。这很简单,这是组件中包含的一个功能,并且state保存在客户端的浏览器存储中。

3 客户端DataTables.net组件

在这里,我将只展示使用DataTables组件的ASP.NET视图是什么样子的。

<!-- Employees.cshtml -->
<partial name="_LoadingDatatablesJsAndCss" />

@{
    <div class="text-center">
        <h3 class="display-4">Employees table</h3>
    </div>

    <!-- Here is our table HTML element defined. JavaScript library Datatables
    will do all the magic to turn it into interactive component -->
    <table id="EmployeesTable01" class="table table-striped table-bordered ">
    </table>

}


<script>
    // Datatables script initialization=========================================
    // we used defer attribute on jQuery so it might not be available at this point
    // so we go for vanilla JS event

    document.addEventListener("DOMContentLoaded", InitializeDatatable);

    function InitializeDatatable() {
        $("#EmployeesTable01").dataTable({
            //processing-Feature control the processing indicator.
            processing: true,
            //paging-Enable or disable table pagination.
            paging: true,
            //info-Feature control table information display field
            info: true,
            //ordering-Feature control ordering (sorting) abilities in DataTables.
            ordering: true,
            //searching-Feature control search (filtering) abilities
            searching: true,
            //search.return-Enable / disable DataTables' search on return.
            search: {
                return: true
            },
            //autoWidth-Feature control DataTables' smart column width handling.
            autoWidth: true,
            //lengthMenu-Change the options in the page length select list.
            lengthMenu: [10, 15, 25, 50, 100],
            //pageLength-Change the initial page length (number of rows per page)
            pageLength: 10,

            //order-Initial order (sort) to apply to the table.
            order: [[1, 'asc']],

            //serverSide-Feature control DataTables' server-side processing mode.
            serverSide: true,

            //stateSave-State saving - restore table state on page reload.
            stateSave: true,
            //stateDuration-Saved state validity duration.
            //-1 sessionStorage will be used, while for 0 or greater localStorage will be used.
            stateDuration: -1,

            //Load data for the table's content from an Ajax source.
            ajax: {
                "url": "@Url.Action("EmployeesDT", "Home")",
                "type": "POST",
                "datatype": "json"
            },

            //Set column specific initialisation properties
            columns: [
                //name-Set a descriptive name for a column
                //data-Set the data source for the column from the rows data object / array
                //title-Set the column title
                //orderable-Enable or disable ordering on this column
                //searchable-Enable or disable search on the data in this column
                //type-Set the column type - used for filtering and sorting string processing
                //visible-Enable or disable the display of this column.
                //width-Column width assignment.
                //render-Render (process) the data for use in the table.
                //className-Class to assign to each cell in the column.

                {   //0
                    name: 'id',
                    data: 'id',
                    title: "Employee Id",
                    orderable: true,
                    searchable: false,
                    type: 'num',
                    visible: true
                },
                {
                    //1
                    name: 'givenName',
                    data: "givenName",
                    title: "Given Name",
                    orderable: true,
                    searchable: true,
                    type: 'string',
                    visible: true
                },
                {
                    //2
                    name: 'familyName',
                    data: "familyName",
                    title: "Family Name",
                    orderable: true,
                    searchable: true,
                    type: 'string',
                    visible: true
                },
                {
                    //3
                    name: 'town',
                    data: "town",
                    title: "Town",
                    orderable: true,
                    searchable: true,
                    type: 'string',
                    visible: true
                },
                {
                    //4
                    name: 'country',
                    data: "country",
                    title: "Country",
                    orderable: true,
                    searchable: true,
                    type: 'string',
                    visible: true
                },
                {
                    //5
                    name: 'email',
                    data: "email",
                    title: "Email",
                    orderable: true,
                    searchable: true,
                    type: 'string',
                    visible: true,
                    width: "150px",
                    className: 'text-center '
                },
                {
                    //6
                    name: 'phoneNo',
                    data: "phoneNo",
                    title: "Phone Number",
                    orderable: false,
                    searchable: true,
                    type: 'string',
                    visible: true
                },
                {
                    //7
                    name: 'actions',
                    data: "actions",
                    title: "Actions",
                    orderable: false,
                    searchable: false,
                    type: 'string',
                    visible: true,
                    render: renderActions
                },
                {
                    //8
                    name: 'urlForEdit',
                    data: "urlForEdit",
                    title: "urlForEdit",
                    orderable: false,
                    searchable: false,
                    type: 'string',
                    visible: false
                }
            ]
        });

        function renderActions(data, type, row, meta) {
            //for Edit button we get Url from the table data
            let html1 =
                '<a class="btn btn-info" href="' +
                row.urlForEdit + '">Edit</a>';

            //for Info button we create Url in JavaScript
            let infoUrl = "@Url.Action("EmployeeInfo", "Home")" +
                "?EmployeeId=" + row.id;
            let html2 =
                '<a class="btn btn-info"  style="margin-left: 10px" href="' +
                infoUrl + '">Info</a>';

            return html1 + html2;
        }
    }
</script>

注意DataTables组件配置中的“stateSave”和“stateDuration”属性。他们只需要激活即可使用该功能。

  • 属性stateSave——状态保存——在页面重新加载时恢复表状态。
  • 属性stateDuration——保存的状态有效期。如果设置为-1,则将使用sessionStorage,而对于0或更大,将使用localStorage。

有关这些属性的更多信息,请参阅手册[1]。这里的应用程序只是ASP.NET环境的概念证明。

4 保存状态如何运作

从内部观察事物的运作方式总是很有趣。使用Chrome DevTools,我们可以窥探浏览器的会话存储。

您可以看到,DataTables.net组件已为自己为该特定URL创建了一个键,因为可能有多个页面包含该组件DataTables.net并且每个页面都需要保留自己的状态。你可以看到状态保存在一个大的JSON中,并且有我们的搜索短语“mark”和“order by column 2, descending”设置。

5 总结

可以下载完整的示例代码项目。

6 参考资料

[1] DataTables | Javascript table library

https://www.codeproject.com/Articles/5385308/ASP-NET8-using-DataTables-net-Part3-State-saving

假人有限元模型 假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用 立即下载

相关推荐

从涡流求解器到瞬态场:Maxwell 3D里无线充电仿真,选对求解器能省一半计算时间

本文深入探讨了Maxwell 3D在无线充电仿真中涡流求解器与瞬态求解器的选择策略,帮助工程师优化计算效率与精度。通过对比分析两种求解器的适用场景、性能差异及实战技巧,揭示如何根据频率特性、材料非线性和动态过程需求做出精准选择,可节省高达50%的计算时间。特别针对3D线圈模型的无线充电系统设计提供了专业建议。

weixin_26861329的博客 244

使用DataTables.net的ASP.NET 8——第1部分——基础

构建使用jQuery组件DataTables.net的ASP.NET 8 MVC应用程序的实用指南。本文重点介绍如何将不同的技术(ASP.NET 8、MVC、C#、Bootstrap 5、jQuery DataTables.net)集成到专业级应用程序中。

寒冰屋的专栏 984

WPF 解决listview值更改时页面没有刷新

WPF 解决listview值更改时页面没有刷新。

weixin_52475977的博客 1390

使用DataTables.net的ASP.NET8——第4部分——多语言

构建使用jQuery组件DataTables.net的Asp.Net 8 MVC应用程序的实用指南。

寒冰屋的专栏 414

STM32F4XX软件模拟I2C实现MPU6050姿态数据采集

本文详细介绍了在STM32F4XX平台上通过软件模拟I2C驱动MPU6050传感器实现姿态数据采集的完整方案。内容涵盖软件I2C的GPIO配置、核心通信函数实现、MPU6050寄存器配置详解以及数据读取处理流程,为硬件资源受限的嵌入式应用提供了灵活的解决方案,并分享了调试技巧与常见问题处理方法。

butter的博客 680

LVGL 9.4 性能调优实战:如何通过脏区合并与tile分块,让你的嵌入式UI流畅度翻倍

本文深入探讨LVGL 9.4中的性能优化技术,重点介绍脏区合并与tile分块如何显著提升嵌入式UI流畅度。通过实战案例和源码分析,详细解析局部刷新策略、显示框架调优及性能瓶颈诊断方法,帮助开发者在STM32、ESP32等资源受限设备上实现丝滑的UI体验。

weixin_28678831的博客 455

使用DataTables.net的ASP.NET8——第6部分——在AJAX中返回其他参数

构建使用jQuery组件DataTables.net的Asp.Net 8 MVC应用程序的实用指南。

寒冰屋的专栏 442

无源定位之时差估计的精确时差估计算法(ETDE)及MATLAB实现程序

时差估计算法之精确时差估计(ETDE)欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入 欢迎使用Markdown编辑器 你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想

伊谢尔伦的林中小路 4260

使用DataTables.net的ASP.NET8——第5部分——在AJAX中传递其他参数

构建使用jQuery组件DataTables.net的Asp.Net 8 MVC应用程序的实用指南。

寒冰屋的专栏 481

55、宇宙微波背景辐射望远镜及其光学系统解析

本文详细解析了宇宙微波背景辐射(CMB)望远镜及其光学系统的设计与优化。内容涵盖折射与反射光学系统的特性、旁瓣控制技术、气球与地面观测系统的对比、探测器阵列的发展、光学系统设计流程以及不同观测场景下的光学系统选择。同时,文章展望了CMB望远镜光学系统的未来发展趋势,包括技术创新、多频段观测、国际合作与大型项目等。通过系统性的分析与对比,为CMB研究提供了全面的技术支持与理论基础。

f9g0h的博客 149

UCIE Specification详解(七)

Logical Physical Layer(逻辑物理层)

Crazzy_M的博客 1703

使用DataTables.net的ASP.NET8——第9部分——高级过滤器

构建使用jQuery组件DataTables.net的Asp.Net 8 MVC应用程序的实用指南。

寒冰屋的专栏 482

Android 13.0 framework默认沉浸式导航栏功能实现

​ 在13.0的系统rom定制化开发中,在实现导航栏的某些定制化开发中,在某些产品需要实现沉浸式导航栏,就是需要app 能全屏显示同样也能显示导航栏,接下来就来分析下相关的功能实现 ​

安卓兼职framework和app工程师的博客 475

使用DataTables.net的ASP.NET8 ——第2部分——操作按钮

构建使用jQuery组件DataTables.net的Asp.Net 8 MVC应用程序的实用指南。

寒冰屋的专栏 357

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

使用DataTables.net的ASP.NET8——第8部分——选择行

构建使用jQuery组件DataTables.net的ASP.NET 8 MVC应用程序的实用指南。

寒冰屋的专栏 327

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

ASP.NET MVC 中使用 jQuery DataTables 教程

ASP.NET MVC 中使用 jQuery DataTables 教程 项目介绍 Mvc.JQuery.DataTables 是一个开源项目,旨在简化 ASP.NET MVC 应用程序中将 IQueryable 数据源与流行的 jQuery DataTables 插件集成的过程。它提供了一系列辅助方法,允许开发者轻松地将复杂的表格功能(如过滤、排序、分页及自定义渲染)添加到基于控制器的视图中,...

gitblog_00662的博客 672

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

使用DataTables.net的ASP.NET8——第7部分——常规按钮

构建使用jQuery组件DataTables.net的Asp.Net 8 MVC应用程序的实用指南。

寒冰屋的专栏 324

**ASP.NET MVC 中使用 DataTables.net 的指南**

ASP.NET MVC 中使用 DataTables.net 的指南 该项目 mcintyre321/mvc.jquery.datatables 是一个ASP.NET MVC的辅助库,旨在简化将IQueryable数据源与功能丰富的jQuery DataTables插件集成的过程。以下是本指南的详细内容: 1. 目录结构及介绍 仓库的目录结构设计是为了支持快速集成和自定义,主要组成部分如下: ...

gitblog_00137的博客 481

Datatables.AspNet:简化ASP.NET中的数据表处理

Datatables.AspNet:简化ASP.NET中的数据表处理 在当今快节奏的开发环境中,处理数据表格往往成为开发者不得不面对的一项繁琐任务。但有了Datatables.AspNet这一强大的开源库,中高级开发者们终于可以告别那些冗长乏味的数据绑定和参数处理工作了。自2014年初具雏形以来,该项目历经全面重写,现已支持ASP.NET MVC、Web API以及ASP.NET Core,为全....

gitblog_00617的博客 1028

ASP.NET JQuery Datatables Server

ASP.NET JQuery Datatables Server Side Integration In this .Net solution, you will find a full working site using the popular JQuery datatables plugin. The solution is served 100% by data from the backend (this is, it uses datatables with its server side op

控件与插件之大全 987

基于 asp.net mvc 的 datatables 应用

Datatables 的简单使用 前言 最近,公司项目使用了Adminlte,一个基于Bootstrap3的响应模板,里面内置了各种组件,日期控件(datepicker,daterangpicker),下拉框(select2),treeview,仪表盘,表格等,其中使用到了datatables。下面来简单说一下datatables的简单使用。 引用的css文件 bundles.Add(new ...

i李泳谦谦谦谦谦 1万+

解决ASP.NET Core MVC中的DataTables渲染问题

本文介绍了ASP.NET Core MVC中使用jQuery DataTables时常见的布局问题及解决方案。主要讨论了在Razor视图中同时显示两个DataTables并添加中间按钮的实现方法,分析了可能导致表格不显示的三个原因:JavaScript执行位置、DataTables配置错误和CSS样式问题。文章提供了具体的代码修改示例,包括正确放置JavaScript代码、调整DataTables配置参数以及优化CSS样式设置,最终实现了两个DataTables和按钮的合理布局展示。

2501_90323865的博客 458

ASP.NET MVC 使用 Datatables (1)

ASP.NET MVC 使用 Datatables (1)具体步骤:1、建立实体类12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758publicclassAsset{publicSystem.Guid Asse...

weixin_30763455的博客 286

ASP.NET MVC 使用 Datatables (2)

ASP.NET MVC 使用 Datatables (2)在服务器端实现分页,排序,获取当前页面数据在上篇的基础上进行改造(datatables的客户端实现)1、修改View页面代码如下:1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575...

weixin_30702887的博客 187

Building an ASP.NET Shopping Cart Using DataTables

Most dynamic Web applications are created for the sole purpose of making money on the Web. Lets face it: why would you go through all the work of creating a dynamic Web application if you dont pla

流男@水孩 1768

了解如何使用ASP.NET Core 3.1构建Web应用程序

ASP.NET Core is an open source web-development framework for building web apps on the .NET platform. While originally only for Windows, it is now available on macOS and Linux as well. ASP.NET Core是一个开...

cumi6497的博客 405
上一篇: 使用DataTables.net的ASP.NET8 ——第2部分——操作按钮
下一篇: 使用DataTables.net的ASP.NET8——第4部分——多语言
寒冰屋
博客等级 码龄18年 1217粉丝 137原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值