<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:wfw="http://wellformedweb.org/CommentAPI/">
<channel>
<title>dwt&#039;s life - layui</title>
<link>https://dwt.life/tag/layui/</link>
<atom:link href="https://dwt.life/feed/tag/layui/" rel="self" type="application/rss+xml" />
<language>zh-CN</language>
<description></description>
<lastBuildDate>Sat, 05 Feb 2022 23:40:41 +0800</lastBuildDate>
<pubDate>Sat, 05 Feb 2022 23:40:41 +0800</pubDate>
<item>
<title>layui 异步数据排序重加载</title>
<link>https://dwt.life/archives/190/</link>
<guid>https://dwt.life/archives/190/</guid>
<pubDate>Sat, 05 Feb 2022 23:40:41 +0800</pubDate>
<dc:creator>Ricky</dc:creator>
<description><![CDATA[&lt;table class=&quot;layui-table&quot; id=&quot;userList-table&quot; lay-filter=&quot;userList-t...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<p><code>&lt;table class=&quot;layui-table&quot; id=&quot;userList-table&quot; lay-filter=&quot;userList-table&quot;&gt;&lt;/table&gt;</code></p><pre><code class="lang-js">layui.use([&#039;form&#039;, &#039;table&#039;, &#039;util&#039;, &#039;config&#039;, &#039;admin&#039;], function () {
      var form = layui.form;
      var table = layui.table;
      var config = layui.config;
      var layer = layui.layer;
      var util = layui.util;
      var admin = layui.admin;
      var  access_token=config.getToken().access_token;

      // 渲染表格
      table.render({
          id:&#039;userList-table&#039;,
          elem: &#039;#userList-table&#039;,
          url: config.base_server + &#039;gameend/userList&#039;,
          method: &#039;GET&#039;,
          where: {
              access_token: access_token
          },
          page: true,
          limit: 100,
          cols: [[
              {type: &#039;numbers&#039;},
              {field: &#039;username&#039;, title: &#039;用户名&#039;},
              {field: &#039;nickname&#039;, sort: false, title: &#039;昵称&#039;},
              {field: &#039;points&#039;, sort: true, title: &#039;积分&#039;},
              {field: &#039;drawnum&#039;, sort: false, title: &#039;抽奖次数&#039;},
              {field: &#039;invitenum&#039;, sort: true, title: &#039;邀请好友数&#039;},
              {field: &#039;ip&#039;, sort: false, title: &#039;ip注册地&#039;},
              {field: &#039;createtime&#039;, sort: false, title: &#039;注册时间&#039;},
              {field: &#039;status&#039;, sort: false, templet: &#039;#userList-tpl-state&#039;, title: &#039;状态&#039;},
              {align: &#039;center&#039;, toolbar: &#039;#userList-table-bar&#039;, title: &#039;操作&#039;},
              {align: &#039;center&#039;, toolbar: &#039;#userInfo-table-bar&#039;, title: &#039;查看详情&#039;},
          ]],
          done: function(res, page, count){
              //如果是异步请求数据方式，res即为你接口返回的信息。
              //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度

              $(&quot;[data-field=&#039;points&#039;]&quot;).each(function(){  
                  $(this).addClass(&quot;points&quot;);
              });
              $(&quot;[data-field=&#039;drawnum&#039;]&quot;).each(function(){
                  $(this).addClass(&quot;drawnum&quot;);
              });
              $(&quot;[data-field=&#039;10&#039;]&quot;).each(function(){
                  $(this).addClass(&quot;ckxq&quot;);
              })


          }
      });


      var type=&quot;&quot;;
      table.on(&#039;sort(userList-table)&#039;, function(obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter=&quot;对应的值&quot;
          // console.log(obj.field); //当前排序的字段名
          //console.log(obj.type); //当前排序类型：desc（降序）、asc（升序）、null（空对象，默认排序）
          //console.log(this); //当前排序的 th 对象

          //type 0 积分降序 1积分升序 2邀请数降序 3邀请数升序
          //
          if(obj.field==&quot;points&quot;){ //积分排序
              if(obj.type==&quot;desc&quot;){ //降序 type=0
                  type=0;
              }else if(obj.type==&quot;asc&quot;){ //升序 type=1
                  type=1;
              }else if(obj.type==null){
                  type=&quot;&quot;;
              }
          }

          if(obj.field==&quot;invitenum&quot;){ //积分排序
              if(obj.type==&quot;desc&quot;){ //降序 type=0
                  type=2;
              }else if(obj.type==&quot;asc&quot;){ //升序 type=1
                  type=3;
              }else if(obj.type==null){
                  type=&quot;&quot;;
              }
          }

          //console.log(type);
　　　　　　table.reload(&#039;userList-table&#039;, {
  　　　　　　  initSort: obj, //记录初始排序，如果不设的话，将无法标记表头的排序状态。 layui 2.1.1 新增参数
   　　　　　　 where: {
   　　　　　　      access_token: access_token,
           　　　　 type:type
    　　　　}});
　　
      });

     
  });</code></pre>
]]></content:encoded>
<slash:comments>0</slash:comments>
<comments>https://dwt.life/archives/190/#comments</comments>
<wfw:commentRss>https://dwt.life/feed/tag/layui/</wfw:commentRss>
</item>
</channel>
</rss>