how do you pass parameters in asmx using Flexigrid?

拜拜、爱过 提交于 2020-01-02 08:29:22

问题


here's my code:

$('#flex1').flexigrid({
            method: 'POST',
            url: '/services/MHService.asmx/GetSurgicalHistory',
            dataType: 'xml',
            colModel: [
                    { display: 'Surgical Procedure', name: 'SurgicalProcedure', width: 120, sortable: true, align: 'left' },
                    { display: 'Notes', name: 'Notes', width: 120, sortable: true, align: 'left' },
                    { display: 'Complications', name: 'Complications', width: 120, sortable: true, align: 'left' }
                ],
            searchitems: [
                    { display: 'Surgical Procedure', name: 'SurgicalProcedure' },
                    { display: 'Notes', name: 'Notes' },
                    { display: 'Complications', name: 'Complications' }
                ],
            sortname: 'SurgicalProcedure',
            singleSelect: true,
            sortorder: 'asc',
            usepager: true,
            title: 'Surigcal History',
            useRp: true,
            rp: 10,
            showTableToggleBtn: true,
            width: 805,
            height: 200
        });

Now this code works, how do i pass parameters in the webservice? i tried looking for the 'data' parameter in the Flexigrid api, but there seems to be none.

something like this:

            method: 'POST',
            url: '/services/MHService.asmx/GetSurgicalHistory',
            dataType: 'xml',
            data: '{ id: 23, area: "anywhere" }',

回答1:


what I ended up doing was this on line 713 of flexigrid.js i add this

            for(opt in p.optional){
              param[param.length] = {name:opt,value:p.optional[opt]};
            }

then I could do something like this

 $('#flex1').flexigrid({
        method: 'POST',
        url: '/services/MHService.asmx/GetSurgicalHistory',
        dataType: 'xml',
        colModel: [
                { display: 'Surgical Procedure', name: 'SurgicalProcedure', width: 120, sortable: true, align: 'left' },
                { display: 'Notes', name: 'Notes', width: 120, sortable: true, align: 'left' },
                { display: 'Complications', name: 'Complications', width: 120, sortable: true, align: 'left' }
            ],
        searchitems: [
                { display: 'Surgical Procedure', name: 'SurgicalProcedure' },
                { display: 'Notes', name: 'Notes' },
                { display: 'Complications', name: 'Complications' }
            ],
        sortname: 'SurgicalProcedure',
        singleSelect: true,
        sortorder: 'asc',
        usepager: true,
        title: 'Surigcal History',
        useRp: true,
        rp: 10,
        showTableToggleBtn: true,
        width: 805,
        height: 200,
        optional: { id: 23, area: "anywhere" }
    });

its not great but I really could find any other way and I don't see any new versions coming out anytime soon 8 ^ )




回答2:


Change:

data: '{ id: 23, area: "anywhere" }',

to:

params: [{name:'id', value: 23},{name:'area', value: 'anywhere'}],

Or if you want to reload with new Options:

$("#flex1").flexOptions({params: [{name:'id', value: 23},{name:'area', value: 'anywhere'}]}).flexReload();



回答3:


Additional parameters can be specified using the params: option. If you look at line 615-618 in flexigrid.js, you can see where the code loops through each item in p.params, and adds it to the default list (page, rp, sortname, etc).




回答4:


You should try this here:

http://bargaorobalo.net/blog/flexigrid-passar-parametros

Its in portuguese, but means that you PASS additionals parameters to json:

useRp   : true,
rp  : 10,
params: [{name:'ID', value: 100}]

and RECEIVE in json setting variable:

$query     = isset($_POST['query'])     ? $_POST['query']    : false;
$qtype     = isset($_POST['qtype'])     ? $_POST['qtype']    : false;
$id = isset($_POST['ID']) ? $_POST['ID'] : NULL;

Now, you just use this parameter in your SQL CODE:

$sql = "SELECT * FROM PROCEDURE_NAME(".$id.") $where $sort $limit";
$result = runSQL($sql);



回答5:


if you try to load flexigrid data for a particular value in some click Event. try this we can use the query string like a

 var val1=value;
    url: '/services/MHService.asmx/GetSurgicalHistory?qurid='+val1,

to the webservice method and get from webservice using string

getvalue=HttpContext.Current.Request.QueryString["qurid"].ToString();




回答6:


You can use the flexOptions in the onSubmit event when initializing flexigrid, like this:

...
title: 'Surigcal History',
onSubmit: function() {  
  $('#flex1').flexOptions({newp:1,params:[{name: 'id', value: '23'}]});
  $('#flex1').flexOptions({newp:1,params:[{name: 'area', value: 'anywhere'}]});
},
useRp: true,
...

better to use a loop for multiple parameters

This avoids modifying the flexigrid.js directly



来源:https://stackoverflow.com/questions/3323865/how-do-you-pass-parameters-in-asmx-using-flexigrid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!