gpt4 book ai didi

javascript - 在 jsGrid 中创建日期字段的正确方法

转载 作者:行者123 更新时间:2023-11-30 11:53:13 29 4
gpt4 key购买 nike

所以我是初学者,使用 jsGrid 制作日历网格,看起来像这样 http://i.stack.imgur.com/gU4V9.png

我已经这样创建了标题字段:

var headerFields = [{ 
name: "name",
title: "", type: "text",
width: 60
}];

for(var i = 1; i <= 31; i++){
headerFields[i] = {
name: String(i),
title: String(i),
type: "text",
width: 20,
sorting: false,
inserting: false
};
}

headerFields.push({ type: "control", width: 24, editButton: false });

然后在 jsGrid 本身中初始化:

$("#jsGrid").jsGrid({
...
fields: headerFields,
...
}

除了所有月份都有 31 天之外,我觉得这是一种非常不符合犹太洁食标准的方式,因为如果我想在某一天引用一个单元格,它就像“item[17]”一样完成,这是非常模棱两可的,感觉它应该有另一层,如“item.day(17)”,但我很难弄清楚如何应用它。

有什么想法吗?

最佳答案

jsgrid 日期字段的工作示例

var db = {

loadData: function(filter) {
return $.grep(this.users, function(user) {
return (!filter.Name || user.Name.indexOf(filter.Name) > -1);
});
},

insertItem: function(item) {
this.users.push(item);
},

deleteItem: function(item) {
var index = $.inArray(item, this.users);
this.users.splice(index, 1);
}

};

window.db = db;

db.users = [
{
"Account": "D89FF524-1233-0CE7-C9E1-56EFF017A321",
"Name": "Prescott Griffin",
"RegisterDate": "2011-02-22T05:59:55-08:00"
},
{
"Account": "06FAAD9A-5114-08F6-D60C-961B2528B4F0",
"Name": "Amir Saunders",
"RegisterDate": "2014-08-13T09:17:49-07:00"
},
{
"Account": "EED7653D-7DD9-A722-64A8-36A55ECDBE77",
"Name": "Derek Thornton",
"RegisterDate": "2012-02-27T01:31:07-08:00"
},
{
"Account": "2A2E6D40-FEBD-C643-A751-9AB4CAF1E2F6",
"Name": "Fletcher Romero",
"RegisterDate": "2010-06-25T15:49:54-07:00"
},
{
"Account": "3978F8FA-DFF0-DA0E-0A5D-EB9D281A3286",
"Name": "Thaddeus Stein",
"RegisterDate": "2013-11-10T07:29:41-08:00"
}
];

var MyDateField = function (config) {
jsGrid.Field.call(this, config);
};

MyDateField.prototype = new jsGrid.Field({

sorter: function (date1, date2) {
return new Date(date1) - new Date(date2);
},

itemTemplate: function (value) {
return new Date(value).toDateString();
},

insertTemplate: function (value) {
return this._insertPicker = $("<input class='date-picker'>").datetimepicker();
},

editTemplate: function (value) {
return this._editPicker = $("<input class='date-picker'>").datetimepicker();
},

insertValue: function () {
return this._insertPicker.data("DateTimePicker").useCurrent();
},

editValue: function () {
return this._editPicker.data("DateTimePicker").useCurrent();
}
});

jsGrid.fields.date = MyDateField;

$("#jsGrid").jsGrid({
height: "90%",
width: "100%",

inserting: true,
filtering: true,
editing: true,
paging: true,

autoload: true,

controller: db,

fields: [
{ name: "Account", width: 150, align: "center" },
{ name: "Name", type: "text" },
{ name: "RegisterDate", type: "date", width: 100, align: "center" },
{ type: "control", editButton: false }
]
});

引用:http://jsfiddle.net/tabalinas/L6wbmvfo/

关于javascript - 在 jsGrid 中创建日期字段的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38850708/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com