jQWidgets Forums

Forum Replies Created

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • in reply to: Dynamic columns Grid Dynamic columns Grid #28359

    frankfu
    Member

    Hi peter:

    thank you very much.
    you are right, i add just

    source.datafields=[]
    before source.url = “beverages2.txt”;
    and it works.

    frankfu

    in reply to: Dynamic columns Grid Dynamic columns Grid #28335

    frankfu
    Member

    Hello peter
    i have do some test but still doesn’t works, can you help me to find de problem?

    i use an exemple demo of jqwidgets and just add a button to change the source.

    <script type="text/javascript">
    $(document).ready(function () {
    var theme = getDemoTheme();
    var url = "beverages.txt";
    // prepare the data
    var source =
    {
    datatype: "json",
    id: 'id',
    url: url
    };
    $("#jqxgrid").jqxGrid(
    {
    width: 670,
    source: source,
    theme: theme,
    columnsresize: true,
    columns: [
    { text: 'Name', datafield: 'name', width: 250 },
    { text: 'Beverage Type', datafield: 'type', width: 250 },
    ]
    });
    $("#jqxButton").jqxButton({ width: '150', theme: theme });
    $("#jqxButton").on('click', function () {
    source.url = "beverages2.txt";
    $("#jqxgrid").jqxGrid(
    {
    source: source,
    columns: [
    { text: 'Name', datafield: 'name2', width: 250 },
    { text: 'Beverage Type', datafield: 'type2', width: 250 },
    ]
    })
    });
    });
    </script>

    the txt file beverages.txt is

    [{
    "id": "1",
    "name": "Hot Chocolate",
    "type": "Chocolate Beverage"
    }, {
    "id": 2,
    "name": "Peppermint Hot Chocolate",
    "type": "Chocolate Beverage"
    }]

    the txt file beverages2.txt is

    [{
    "id": "1",
    "name2": "Hot Chocolate2",
    "type2": "Chocolate Beverage2"
    }, {
    "id": 2,
    "name2": "Peppermint Hot Chocolate2",
    "type2": "Chocolate Beverage2"
    }]

    thank you very much for your help

    in reply to: Dynamic columns Grid Dynamic columns Grid #28320

    frankfu
    Member

    thank you for your sugestion, it work with your method.

    on the other hand, i met a problem when i refresh the grid

    <script type="text/javascript">
    $(document).ready(function () {
    var theme = getDemoTheme();
    // rules data
    var url = "/appproject/savedata/";
    var source =
    {
    datatype: 'json',
    root : 'rowsinfo',
    url :url,
    cache: false,
    columns:[],
    beforeprocessing: function (data) {
    alert("before")
    var columnsdata = new Array();
    for (k in data.columnsinfo){
    var col={};
    col.text = data.columnsinfo[k]["text"];
    col.datafield = data.columnsinfo[k]["datafield"];
    columnsdata.push(col);
    source.columns = columnsdata
    }
    $("#jqxgrid").jqxGrid({columns : source.columns});
    },
    data: {
    startcolumn: 1,
    }
    };
    // creage jqxgrid
    $("#jqxgrid").jqxGrid(
    {
    width: 970,
    source: source,
    theme: theme,
    });
    $("#jqxButton").jqxButton({ width: '150', theme: theme });
    $("#jqxButton").on('click', function () {
    source.data.startcolumn = 20;
    $("#jqxgrid").jqxGrid({source: source})
    });
    });
    </script>

    the Json return by url is like

    {
    columnsinfo: [
    {text: "Acol1",datafield: "Acol1"},
    {text: "Acol2",datafield: "Acol2"},
    {text: "Acol3",datafield: "Acol3"}],
    rowsinfo: [
    {Acol1: "1_1",Acol2: "1_2",Acol3: "1_3"},
    {Acol1: "2_1",Acol2: "2_2",Acol3: "2_3"},
    {Acol1: "3_1",Acol2: "3_2",Acol3: "3_3"}]
    }

    and like this after click the button

    {
    columnsinfo: [
    {text: "Acol20",datafield: "Acol20"},
    {text: "Acol21",datafield: "Acol21"},
    {text: "Acol22",datafield: "Acol22"}
    ],
    rowsinfo: [
    {Acol20: "20_20",Acol21: "20_21",Acol22: "20_22"},
    {Acol20: "21_20",Acol21: "21_21",Acol22: "21_22"},
    {Acol20: "22_20",Acol21: "22_21",Acol22: "22_22"}]
    }

    after click the button, the new json is charged and counted because the columsname in the grid is changed. but the data is empty.
    it seems that is because of the change of the columns name, if the json file returned with the same columns name and with the different data, it works.

    can you help me on this issue?
    thank you very much


    frankfu
    Member

    Hello peter
    thank you for your sugestion. but i am fraid that the syntax of “source.learning[index].rulecontent.constraints” is also wrong.
    can i use source like this?
    how can i get localdata of “source” with json format? thank you


    frankfu
    Member

    Hi Peter Stoev
    thank you for your reponse. in fact, where i met the difficulty is at the part “nestedSource”, because i don’t know how to write to load the data of level “constraints”.

    the setting you have proposed was

         var nestedSource =
    {
    datafields: [
    { name: 'varName', map: 'varName', type: 'string' },
    { name: 'Min', map: 'Min', type: 'string' },
    { name: 'Max', map: 'Max', type: 'string' }
    ],
    datatype: 'json',
    root: 'constraint',
    localdata: data[index].constraints
    };

    i would like a code like

    var url = "rules6.txt";
    var nestedSource =
    {
    datafields: [
    { name: 'varName', map: 'varName', type: 'string' },
    { name: 'Min', map: 'Min', type: 'string' },
    { name: 'Max', map: 'Max', type: 'string' }
    ],
    datatype: 'json',
    root: 'constraint',
    url: url,
    };

    but i have no idea how to load the data like data[index].constraints in this case.

    my json file is rule.txt

    [
    {
    "ruleid": "1001",
    "size": "51",
    "ZScore": "1.21839",
    "complexity": "8",
    "constraints": {
    "constraint": [
    {
    "varName": "BirthWeight",
    "Min": "2.500000",
    "Max": "2.500000"
    },
    {
    "varName": "AgeMother",
    "Min": "39.000000",
    "Max": "39.000000"
    },
    {
    "varName": "AgeFather",
    "Min": "35.000000",
    "Max": "39.000000"
    }
    ]
    }
    },
    {
    "ruleid": "1002",
    "size": "92",
    "ZScore": "2.60137",
    "complexity": "2",
    "constraints": {
    "constraint": [
    {
    "varName": "AgeFather",
    "Min": "32.000000",
    "Max": "45.000000"
    },
    {
    "varName": "Age AD Start (weeks)",
    "Min": "14.000000",
    "Max": "30.000000"
    }
    ]
    }
    },
    ]

    thank you very much

    frankfu


    frankfu
    Member

    Hello,the demo that you gived works well, but i meet a problem when i use url instead of local data. what can i use to replace “localdata: data[index].constraints” if i want to use data source like url: test.json ?

    thank you very much for your help

    frankfu

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