Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I need editable grid in mvc like the jsgrid demo but, I am unable to implement its js file dynamically


JavaScript
(function() {

    var db = {

        loadData: function(filter) {
            return $.grep(this.clients, function(client) {
                return (!filter.Name || client.Name.indexOf(filter.Name) > -1)
                    && (!filter.Age || client.Age === filter.Age)
                    && (!filter.Address || client.Address.indexOf(filter.Address) > -1)
                    && (!filter.Country || client.Country === filter.Country)
                    && (filter.Married === undefined || client.Married === filter.Married);
            });
        },

        insertItem: function(insertingClient) {
            this.clients.push(insertingClient);
        },

        updateItem: function(updatingClient) { },

        deleteItem: function(deletingClient) {
            var clientIndex = $.inArray(deletingClient, this.clients);
            this.clients.splice(clientIndex, 1);
        }

    };

    window.db = db;

    db.countries = [
        { Name: "", Id: 0 },
        { Name: "United States", Id: 1 },
        { Name: "Canada", Id: 2 },
        { Name: "United Kingdom", Id: 3 },
        { Name: "France", Id: 4 },
        { Name: "Brazil", Id: 5 },
        { Name: "China", Id: 6 },
        { Name: "Russia", Id: 7 }
    ];

    db.clients = [
        {
            "ID": "x",
            "Account": "A758A693-0302-03D1-AE53-EEFE22855556",
            "Name": "Carson Kelley",
            "RegisterDate": "2002-04-20T22:55:52-07:00"
        },
        {
            "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"
        },
        {
            "Account": "658DBF5A-176E-569A-9273-74FB5F69FA42",
            "Name": "Nash Knapp",
            "RegisterDate": "2005-06-24T09:11:19-07:00"
        },
        {
            "Account": "76D2EE4B-7A73-1212-F6F2-957EF8C1F907",
            "Name": "Quamar Vega",
            "RegisterDate": "2011-04-13T20:06:29-07:00"
        }
     ];

    }());


I have tried to change js like below but how will I implement filtering and all other method?.If anyone have solution please share.

JavaScript
(function () {
    debugger;
    var db = {

        //loaddata: function (filter) {
        //    return $.grep(this.clients, function (client) {
        //        return (!filter.name || client.name.indexof(filter.name) > -1)
        //            && (!filter.age || client.age === filter.age)
        //            && (!filter.address || client.address.indexof(filter.address) > -1)
        //            && (!filter.country || client.country === filter.country)
        //            && (filter.married === undefined || client.married === filter.married);
        //    });
        //},

        loadData: function (filter) {
            return $.ajax({
                type: "GET",
                url: "/Merchandise/GetMerchandise",
                data: filter,
                dataType: "json"
            });
        },

        

        insertItem: function (insertingClient) {
            this.clients.push(insertingClient);
        },

        updateItem: function (updatingClient) {
            var barcode = updatingClient.Barcode;
            debugger;
        },

        deleteItem: function (deletingClient) {
            debugger;
            //var barcode = deletingClient.Barcode;
            //$.ajax({
            //    type: "Post",
            //    url: "/Merchandise/DeleteMerchandise",
            //    data: { barcode: barcode },
            //    dataType: "json",
            //    success: function (result) {
            //        debugger;
            //    }
            //});
            var clientIndex = $.inArray(deletingClient, this.deletingClient);
            this.deleteItem.splice(clientIndex, 1);
        }

    };

    window.db = db;
    db.countries = [
        { Name: "", Id: 0 },
        { Name: "United States", Id: 1 },
        { Name: "Canada", Id: 2 },
        { Name: "United Kingdom", Id: 3 },
        { Name: "France", Id: 4 },
        { Name: "Brazil", Id: 5 },
        { Name: "China", Id: 6 },
        { Name: "Russia", Id: 7 }];

    db.Locations = [];
    db.damages = [];
    db.clients = [];
    $.get("/Merchandise/GetMerchant",
    function (data) {
        debugger;
        db.Locations = data.lst;
        db.damages = data.lst1;
        db.clients = data.ItemList;
    }, "json");
}());
Posted
Updated 21-Feb-17 20:15pm

1 solution

Hi.,

you have list of values. but you didn't assign the list of field value. please check

fields: [
            { name: "Name", type: "text", width: 150 },
            { name: "Age", type: "number", width: 50 },
            { name: "Address", type: "text", width: 200 },
            { type: "control" }
        ]


Thanks

Best regards
Angappan.S
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900