如何在表格中显示特定月份的数据? [英] How to display data for a specific month in a table?

查看:125
本文介绍了如何在表格中显示特定月份的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在表格中显示特定月份的数据.

I want to know how to display data for a specific month in a table.

有一个带有[EmployeeId,Date,StartTime,EndTime]列的表.我想按日期的月份进行过滤,但是我不知道如何.

There is a table with the column [EmployeeId,Date,StartTime,EndTime]. I want to filter by the month of Date, but I don't know how.

  var AttendanceResult = [];

  // Select employee number and current month data
   var query = app.models.AttendanceMaster.newQuery(); 
   query.filters.EmployeeId._equals = userNumber; // Match employee number
   query.filters.Date._contains = roadMonth;       // Including month

   var records = query.run();  

   for (var i = 0; i < records.length; i++) {
      AttendanceResult.push(records[i]);
   }   

return AttendanceResult;

因为"query.filters.Date._contains = roadMonth;"上面代码中的过滤器不起作用,我认为这里有错误,请告诉我.

Since the "query.filters.Date._contains = roadMonth;" filter in the above code is not working, I think there is an error here, Please tell me.

过滤器有哪些示例?

推荐答案

您当然可以使用appmaker的脚本来实现这一目标.从您的示例中构建,我看到您正在使用服务器脚本.以下代码段应帮助您了解如何实现它,并应产生所需的结果:

You can certainly use appmaker's scripting to achieve this. Building from your example, I see you are using server scripting. The following snippet should help you understand how to achieve it and should also yield the result you desire:

function filterByMonth(month){

  //get the selected month digit
  month = month.toLowerCase();
  var allMonths = {
    "january": 0,
    "february": 1,
    "march": 2,
    "april": 3,
    "may": 4,
    "june": 5,
    "july": 6,
    "august": 7,
    "september": 8,
    "october": 9,
    "november": 10,
    "december": 11
  };
  var monthDigit = allMonths[month];

  // Select employee number and current month data
  var selectedMonthStart = new Date();
  selectedMonthStart.setMonth(monthDigit);
  selectedMonthStart.setDate(1);
  selectedMonthStart.setHours(0,0,-1,0);
  var selectedMonthEnd = new Date();
  selectedMonthEnd.setMonth(monthDigit+ 1);
  selectedMonthEnd.setDate(1);
  selectedMonthEnd.setHours(0,0,0,0);
  var query = app.models.AttendanceMaster.newQuery(); 
  query.filters.EmployeeId._equals = userNumber; // Match employee number
  query.filters.Date._greaterThan = selectedMonthStart; // Including month start time
  query.filters.Date._lessThan = selectedMonthEnd; // Including month end time
  var AttendanceResult = query.run();

  return AttendanceResult; 
}

这篇关于如何在表格中显示特定月份的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆