jQuery UI Widgets Forums Grid Passing parameters to MVC controller

This topic contains 1 reply, has 2 voices, and was last updated by  Dimitar 8 years, 10 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • Passing parameters to MVC controller #83410

    rbrink
    Participant

    Hi,

    I try to pass dynamic parameters to the MVC controller to update the grid values. I have the following code.

    
    var OM000Source = {
            datatype: "json",
            datafields: [
                { name: "accountCode", type: "string" },
                { name: "clientOrderNumber", type: "string" },
                { name: "country", type: "string" },
                { name: "orderStatus", type: "string" },
                { name: "company", type: "string" },
                { name: "orderDate", type: "date" },
                { name: "salesOrderID", type: "string" },
                { name: "processDate", type: "date" },
                { name: "wareHouseStatus", type: "string" },
                { name: "despatchDate", type: "date" }
            ],
            type: "GET",
            url: "OM000_GridData",
            root: "Rows",
           // data: { country: 'Germany', status: '', startdate: '2016-01-01', enddate: '2016-01-07', ordernumber: '' },
          
            id: "salesOrderID",
            beforeprocessing: function (data) {
                OM000Source.totalrecords = data.TotalRows;
            }
        };
    
        //Create the data adaptor fro the input grid
        var OM000SourceDataAdaptor = new $.jqx.dataAdapter(OM000Source, {
            contentType: "application/json; charset=utf-8"
            ,
            formatData: function (data) {
                
                $.extend(data, "{country: 'Germany', status: '',startdate: '2016-01-01', enddate: '2016-01-07', ordernumber: '' }");
                return data;    
            }
          
    
        });
    
        //Create the Input Grid
        $("#jqxOM000Grid").jqxGrid({
            width: "100%",
            source: OM000SourceDataAdaptor,
            selectionmode: "singlerow",
            enablehover: false,
            height: 480,
            pageable: true,
            virtualmode: true,
            columnsresize: true,
            pagesize: 20,
            rendergridrows: function (obj) { return obj.data; },
            columns: [
                { text: "AccountCode", datafield: "accountCode", width: 130 },
                { text: "Order Number", datafield: "clientOrderNumber", width: 100 },
                { text: "Country", datafield: "country", width: 100 },
                { text: "Order Date", datafield: "orderDate", width: 200, cellsformat: "dd/MM/yyyy" },
                { text: "Despatch Date", datafield: "despatchDate", width: 200, cellsformat: "dd/MM/yyyy" },
                { text: "Order Status", datafield: "orderStatus", width: 100 },
                { text: "Despatch Status", datafield: "wareHouseStatus", width: 100 },
                { text: "ID", datafield: "salesOrderID", width: 100 }
                ]
    
        });
    

    Controller action

    
    public JsonResult OM000_GridData(int pagenum, int pagesize, string country, string status, DateTime startdate, DateTime enddate, string ordernumber)
            {
                try
                {
                 ...............
    

    If I use the data parameter in the source using hard coded data values the data comes back properly, however if I used the formatData option it fails. Do I do something wrong here as I can’t figure out what I do wrong here. Or better could you give an example how this is going to work with dynamic variables in and MVC environment. I have read your documentation and I still can’t figure it out.
    Thanks
    Richard

    Passing parameters to MVC controller #83479

    Dimitar
    Participant

    Hi Richard,

    Please try the following approach:

    If you have, say, this scenario:

    var currentCountry = 'Germany';
    var currentStatus = '';
    var currentStartdate = '2016-01-01';
    var currentEnddate = '2016-01-07';
    var currentOrdernumber = '';
    
    var OM000Source = {
    
        ...
    
        data: {
            country: currentCountry,
            status: currentStatus,
            startdate: currentStartdate,
            enddate: currentEnddate,
            ordernumber: currentOrdernumber
        },
    
        ...
    
    }

    and when one (or all) of the above variables is changed, call:

    OM000Source.data = {
        country: currentCountry,
        status: currentStatus,
        startdate: currentStartdate,
        enddate: currentEnddate,
        ordernumber: currentOrdernumber
    };

    to update the data parameter, too.

    We hope this solution helps you.

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.