admin管理员组

文章数量:1416075

I am using kendo grid for my web portal code for grid is

 //Grid for award adding
    var griddataSource = new kendo.data.DataSource({
        dataType: "json",
        transport: {
            read: function(o){
                    //o.success([]);
                    url: ServiceBaseUrl+"/Magazine/getsubscriptiondetails?magazineid="+magazine_id, 
                    dataType: "json",
                },
            create: function(o) {                      
                var item = o.data;
                //assign a unique ID and return the record
                item.id =  len;
                o.success(item);
                len++;
            },
            destroy: function(o) {
                o.success();
            },
            update: function(o){
                o.success();
            }         
        },                      
        autoSync: false,
        schema: {                       
        model: {
        id    : "id",
        fields: {

                        magazine_subscription_id: { editable: true},
                        no_of_issues:{editable: true, type:"number", validation: {
                            required: {
                                message: "No of issues required"
                            },
                            min: 1
                        }
                        },
                        subscription_name: { editable: true, type:"string", validation: {
                            required: {
                                message: "Package Name required"
                            }
                            } 
                        },
                        subscription_key: { editable: true, type:"string", validation: { 
                            required: {
                                message: "Subscription Key required"
                            }
                        } },
                        price_inr: { type: "number", validation: { 
                            required: {
                                message: "Price(INR) Key required"
                            }, min: .1} },
                        price: { type: "number", validation: { 
                            required: {
                                message: "Price($) Key required"
                            },
                            min: .1} },
                        discount_type: { type:"string", editable: true, nullable: false},
                        discount_no_of_free_issue: { type: "number" ,validation: { min: 1}}

        }      
        }
        }
    });

    $("#grid").kendoGrid({
    dataSource: griddataSource,
    pageable: false,
    selectable: "multiple",
    sortable: true,
    filterable: false,
    reorderable: true,
    scrollable: false,
    toolbar: ["create"],

    columns: 
    [
        { field: "no_of_issues", title: "No. of issues", width: "100px", format: ""},
        { field: "subscription_name", title: "Package Name", width: "150px" },
        { field: "subscription_key", title: "Subscription Key", width: "150px" },
        { field: "price_inr", title: "Price (INR)", width: "75px" },
        { field: "price", title: "Price ($)", width: "75px" },
        { field: "discount_type", title: "Type", width: "150px", values: type},
        { field: "discount_no_of_free_issue", title: "Discount / No. of Issues", width: "150px", format: ""},
        { mand: ["edit", "destroy"], title: " ", width: "210px" }
    ],
    editable: "inline"
    });

the grid display the content correctly. but when i add a new record in to the grid then show an error that

 Uncaught SyntaxError: Unexpected number

if any one know this please help me

thanks in advance

I am using kendo grid for my web portal code for grid is

 //Grid for award adding
    var griddataSource = new kendo.data.DataSource({
        dataType: "json",
        transport: {
            read: function(o){
                    //o.success([]);
                    url: ServiceBaseUrl+"/Magazine/getsubscriptiondetails?magazineid="+magazine_id, 
                    dataType: "json",
                },
            create: function(o) {                      
                var item = o.data;
                //assign a unique ID and return the record
                item.id =  len;
                o.success(item);
                len++;
            },
            destroy: function(o) {
                o.success();
            },
            update: function(o){
                o.success();
            }         
        },                      
        autoSync: false,
        schema: {                       
        model: {
        id    : "id",
        fields: {

                        magazine_subscription_id: { editable: true},
                        no_of_issues:{editable: true, type:"number", validation: {
                            required: {
                                message: "No of issues required"
                            },
                            min: 1
                        }
                        },
                        subscription_name: { editable: true, type:"string", validation: {
                            required: {
                                message: "Package Name required"
                            }
                            } 
                        },
                        subscription_key: { editable: true, type:"string", validation: { 
                            required: {
                                message: "Subscription Key required"
                            }
                        } },
                        price_inr: { type: "number", validation: { 
                            required: {
                                message: "Price(INR) Key required"
                            }, min: .1} },
                        price: { type: "number", validation: { 
                            required: {
                                message: "Price($) Key required"
                            },
                            min: .1} },
                        discount_type: { type:"string", editable: true, nullable: false},
                        discount_no_of_free_issue: { type: "number" ,validation: { min: 1}}

        }      
        }
        }
    });

    $("#grid").kendoGrid({
    dataSource: griddataSource,
    pageable: false,
    selectable: "multiple",
    sortable: true,
    filterable: false,
    reorderable: true,
    scrollable: false,
    toolbar: ["create"],

    columns: 
    [
        { field: "no_of_issues", title: "No. of issues", width: "100px", format: ""},
        { field: "subscription_name", title: "Package Name", width: "150px" },
        { field: "subscription_key", title: "Subscription Key", width: "150px" },
        { field: "price_inr", title: "Price (INR)", width: "75px" },
        { field: "price", title: "Price ($)", width: "75px" },
        { field: "discount_type", title: "Type", width: "150px", values: type},
        { field: "discount_no_of_free_issue", title: "Discount / No. of Issues", width: "150px", format: ""},
        { mand: ["edit", "destroy"], title: " ", width: "210px" }
    ],
    editable: "inline"
    });

the grid display the content correctly. but when i add a new record in to the grid then show an error that

 Uncaught SyntaxError: Unexpected number

if any one know this please help me

thanks in advance

Share Improve this question asked Apr 3, 2013 at 8:37 deepu sankardeepu sankar 4,4653 gold badges28 silver badges38 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

As I can see in basic sample , parameter width of column definition should be a number instead of string

 { field: "no_of_issues", title: "No. of issues", width: 100 },

UPD: as Pavel Petrman said, now it's acceptable to use string width, to set proper scale. For example here author used "px", and you can use relative points ("100%") as well.

I've just had this very problem. The problem was very easy to solve yet very hard to track down. So I got rid of the error by supplying

create: function(options) {    
    options.success({ID:x});
}

where x is something valid (in my case it was a string).

Nevermind that something else is in the object:

options.success({ID:x, foo:bar, ... , stuff: {}, ...})

the important thing is the valid id that corresponds with your model id settings (again, in my case

schema: {
    model: {
       id: "ID",

).

So regarding this particular question, I'd check the len parameter.

I got this kind of error with the wrong column mapping. I had

 columns: [
 {
     field: 'Name',
     template: vm.categoryNameTreeTemplate
 },
 { field: 'Description' },
 { field: 'Category Code' }, -- this one is wrong
 { field: 'IsDeleted' },
 { mand: ['create', 'edit'] }
]

but the correct version was

columns: [
 {
     field: 'Name',
     template: vm.categoryNameTreeTemplate
 },
 { field: 'Description' },
 { field: 'CategoryCode' },  -- correct
 { field: 'IsDeleted' },
 { mand: ['create', 'edit'] }
]

本文标签: javascriptUncaught SyntaxError Unexpected number in kendo ui gridStack Overflow