【问题标题】:how do i add a datepicker for a backgrid cell如何为 backgrid 单元格添加日期选择器
【发布时间】:2013-09-17 20:22:14
【问题描述】:

我正在研究 backgrid 以实现网格功能,我需要将 datepicker 添加到 backgrid 单元格,而不是使用 Backgrid.DateCell。等待您的回复

示例代码:

           datagrid(collection) : {

                      colomns = [{

                                name : "name",
                    label: "Name",
                    cell : string
                                },
                                {

                                name : "date",
                    label: "Date",
                    cell : string
                                }
                              }],
                        var lgrid = new Backgrid.Grid({
                    columns: columns,
                    collection: collection,
                    emptyText: "no data"
             });
                   this.$("#grids").append(lgrid.render().$el);

                     }

这些是在 backgrid 中定义的列。当我单击日期的字符串单元格时,我需要使用 datepicker 在字符串单元格中填充日期,此时应该打开一个 datepicker,我需要将日期选择到单元格中。请帮帮我....

感谢和问候 甘达哈

【问题讨论】:

    标签: datepicker backgrid


    【解决方案1】:

    onClose 不会在我第一次选择日期时触发。经过第二次尝试,它完美地工作。 我不知道如何解决这个问题。

    【讨论】:

    • 我不认为这是一个答案。如果您还有其他疑问或问题,请发表评论
    • 对不起,我想请不要回答这是我的错误。我正在尝试使用上面的代码。问题是第一次选择日期时 onClose 函数中的 newValue 是空字符串。之后它工作正常。
    【解决方案2】:

    也许有更好的方法来实现它,但我能够这样做。

    MyDatePickerCell = Backgrid.Cell.extend({
        editor: MyDatePickerCellEditor,
    });
    
    MyDatePickerCellEditor = Backgrid.InputCellEditor.extend({
        events:{},
        initialize:function(){
            Backgrid.InputCellEditor.prototype.initialize.apply(this, arguments);
            var input = this;
            $(this.el).datepicker({
                onClose: function(newValue){
                    var command = new Backgrid.Command({});
                    input.model.set(input.column.get("name"), newValue);
                    input.model.trigger("backgrid:edited", input.model, input.column, command);
                    command = input = null;
                }
            });
        },
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-01
      • 2017-12-29
      • 1970-01-01
      相关资源
      最近更新 更多