【问题标题】:How to search w2ui date between如何在 w2ui 之间搜索日期
【发布时间】:2020-03-06 21:07:51
【问题描述】:

我有使用 w2ui javascript 的表,记录中有数据 json。我无法使用运算符按日期搜索,此代码不起作用。但是当我使用 operator is 和一个参数时它就起作用了。我不知道这段代码有什么问题。我想念什么?

$(function() {
  $('#grid').w2grid({
    name: 'grid',
    columns: [
      { field: 'recid', caption: 'ID', size: '50px', sortable: true }, 
      { field: 'fname', caption: 'First Name', size: '30%', sortable: true },
      { field: 'lname', caption: 'Last Name', size: '30%', sortable: true }, 
      { field: 'email', caption: 'Email', size: '40%' }, 
      { field: 'sdate', caption: 'Start Date', size: '120px', render:'date', type: 'date' }],
    records: [{
      recid: 1,
      fname: 'John',
      lname: 'doe',
      email: 'jdoe@gmail.com',
      sdate: '4/3/2012'
    }, {
      recid: 2,
      fname: 'Stuart',
      lname: 'Motzart',
      email: 'jdoe@gmail.com',
      sdate: '4/3/2012'
    }, {
      recid: 3,
      fname: 'Jin',
      lname: 'Franson',
      email: 'jdoe@gmail.com',
      sdate: '4/3/2012'
    }, {
      recid: 4,
      fname: 'Susan',
      lname: 'Ottie',
      email: 'jdoe@gmail.com',
      sdate: '4/3/2012'
    }, {
      recid: 5,
      fname: 'Kelly',
      lname: 'Silver',
      email: 'jdoe@gmail.com',
      sdate: '4/3/2012'
    }, {
      recid: 6,
      fname: 'Francis',
      lname: 'Gatos',
      email: 'jdoe@gmail.com',
      sdate: '4/3/2012'
    }, {
      recid: 7,
      fname: 'Mark',
      lname: 'Welldo',
      email: 'jdoe@gmail.com',
      sdate: '4/3/2012'
    }, {
      recid: 8,
      fname: 'Thomas',
      lname: 'Bahh',
      email: 'jdoe@gmail.com',
      sdate: '4/7/2012'
    }, {
      recid: 9,
      fname: 'Sergei',
      lname: 'Rachmaninov',
      email: 'jdoe@gmail.com',
      sdate: '4/6/2012'
    }, {
      recid: 10,
      fname: 'Jill',
      lname: 'Doe',
      email: 'jdoe@gmail.com',
      sdate: '4/5/2012'
    }]
  });
 	
});

function search1() {
    w2ui['grid'].search([{ field: 'sdate', value: ['4/5/2012', '4/7/2012'], type: 'date', operator: 'between'}]);
 }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://w2ui.com/src/w2ui-1.3.min.js"></script>
<link href="http://w2ui.com/src/w2ui-1.3.min.css" rel="stylesheet"/>

<div id="grid" style="width: 100%; height: 350px;"></div>
<br />
Date: <input type="text" name="sDate"> <input type="text" name="eDate">
<input type="submit" value="Submit" onclick="search1()">

【问题讨论】:

  • 我认为问题出在日期格式上。
  • 你能解决它吗?我不知道你介意什么@YiğitYüksel

标签: javascript jquery html w2ui


【解决方案1】:

搜索属性必须按每列的类型定义

例如。

 searches: [
            { field: 'recid', caption: 'ID ', type: 'int' },
            { field: 'lname', caption: 'Last Name', type: 'text' },
            { field: 'fname', caption: 'First Name', type: 'text' },
            { field: 'email', caption: 'Email', type: 'list', options: { items:[ 'jim@gmail.com', 'jdoe@gmail.com']} },
            { field: 'sdate', caption: 'Start Date', type: 'date' }
 ],

【讨论】:

    猜你喜欢
    • 2012-09-30
    • 2019-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多