代码之家  ›  专栏  ›  技术社区  ›  rjmartin

使devextreme datagrid与webpack协同工作

  •  0
  • rjmartin  · 技术社区  · 6 年前

    我只是想让一个简单的演示应用程序使用webpack和devextreme组件。我先在没有webpack的情况下构建了这个应用程序,一切正常。我正在尝试重构它以使用Webpack。我无法让datagrid页正常工作我只是得到一个控制台错误。dxdatagrid不是一个函数。如果有人知道我错在哪里,任何想法都会很好。

    var $ = require('jquery');
    var ko = require('knockout');
    
    require('devextreme/integration/knockout');
    
    require('devextreme/ui/data_grid');
    
    require('devextreme/ui/form');
    
    require('devextreme/ui/text_box');
    require('devextreme/ui/button');
    require('devextreme/ui/check_box');
    require('devextreme/ui/popup');
    
    var AspNetData = require('devextreme-aspnet-data/js/dx.aspnet.data');
    
    $(function () {
        var url = CONST_URL + 'Login/';
    
        $("#userGrid").dxDataGrid({
            showColumnLines: false,
            showRowLines: true,
            rowAlternationEnabled: true,
            columnHidingEnabled: true,
            showBorders: true,
            dataSource: AspNetData.createStore({
                key: "id",
                loadUrl: url + "GetUsers",
                insertUrl: url + "UpsertUser",
                updateUrl: url + "UpsertUser",
                deleteUrl: url + "DeleteUser"
            }),
            columnChooser: {
                //enabled: true,
                //mode: "select"
            },
            paging: {
                pageSize: 5
            },
            pager: {
                showPageSizeSelector: true,
                //allowedPageSizes: [5, 10, 15],
                showInfo: true
            },
            editing: {
                allowUpdating: true,
                mode: "form",
                allowAdding: true,
                allowDeleting: true
            },
            columns: [
                {
                    dataField: "id",
                    caption: "User ID",
                    formItem: {
                        visible: false
                    },
                    hidingPriority: 1
                },
                {
                    dataField: "username",
                    caption: "Username",
                    validationRules: [{
                        type: "required",
                        message: "Username"
                    }, {
                            type: 'pattern',
                            pattern: /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/,
                            message: 'Please supply a valid email address.'
                        }],
                    formItem: {
                        visible: true
                    },
                    hidingPriority: 3
                },
                {
                    dataField: "password",
                    caption: "password",
                    mode: "password",
                    validationRules: [{
                        type: "required",
                        message: "Password",
                    }, {
                            type: "stringLength",
                            min: 8,
                            message: "Your password must have at least 8 characters."
                        }],
                    visible: false,
                    formItem: {
                        visible: true
                    }
                },
                {
                    dataField: "date_created",
                    caption: "Date Created",
                    formItem: {
                        visible: false
                    },
                    hidingPriority: 2
                },
                {
                    dataField: "is_locked",
                    caption: "User Locked Out",
                    hidingPriority: 0
                }],
            onEditorPreparing: function (e) {
                if (e.dataField === "password") {
                    e.editorOptions.mode = 'password';
                }
                if (e.parentType === "dataRow" && e.dataField === "username") {
                    setTimeout(function () { $(e.editorElement).dxTextBox("focus") }, 100);
                }
            },
            onToolbarPreparing: function (e) {
                var dataGrid = e.component;
    
                e.toolbarOptions.items.unshift({
                    location: "before",
                    template: function () {
                        return $("<div/>")
                            .append(
                                $("<h2 />")
                                    .text("User List")
                            );
                    }
                });
            },
            onEditingStart: function (e) {
                isUpdateCanceled = false;
                e.component.columnOption("date_created", "allowEditing", false);
                e.component.columnOption("id", "allowEditing", false);
            },
            onInitNewRow: function (e) {
                isUpdateCanceled = false;
                e.component.columnOption("date_created", "allowEditing", false);
                e.component.columnOption("id", "allowEditing", false);
                e.component.columnOption("is_locked", "allowEditing", false);
            },
            onContentReady: function (e) {
                var saveButton = $(".dx-button[aria-label='Save']");
                if (saveButton.length > 0)
                    saveButton.click(function (event) {
                        console.log(e.component);
                        if (!isUpdateCanceled) {
                            upsert(e.component);
                            event.stopPropagation();
                        }
                    });
            }
        });
    });
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   rjmartin    6 年前

    devexpress团队给了我解决方案。我想我会把它贴在这里,以防其他人也有同样的问题。我错过了jquery集成。

    require('devextreme/integration/jquery');