jQWidgets Forums

jQuery UI Widgets Forums Grid Localdata, addrow & cellsformat problem

Tagged: ,

This topic contains 1 reply, has 2 voices, and was last updated by  Peter Stoev 5 years, 6 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • Localdata, addrow & cellsformat problem #107540

    emoticon
    Participant

    I have problem with Add/Edit localdata type: ‘JSON’ and cellsformat.
    when I successfuly add or edit new data, the cellsformat doesn’t apply the current cell.

    Then I try to apply this Case to the Code from Sample, but this problem still happen.

    I need your help, thank you

    
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <title id='Description'>This example shows how to create a Grid from JSON data.</title>
        <link rel="stylesheet" href="../../../jqwidgets/styles/jqx.base.css" type="text/css" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <meta name="viewport" content="width=device-width, initial-scale=1 maximum-scale=1 minimum-scale=1" />	
        <script type="text/javascript" src="../../../scripts/jquery-1.12.4.min.js"></script>
        <script type="text/javascript" src="../../../jqwidgets/jqxcore.js"></script>
        <script type="text/javascript" src="../../../jqwidgets/jqxbuttons.js"></script>
        <script type="text/javascript" src="../../../jqwidgets/jqxscrollbar.js"></script>
        <script type="text/javascript" src="../../../jqwidgets/jqxmenu.js"></script>
        <script type="text/javascript" src="../../../jqwidgets/jqxgrid.js"></script>
        <script type="text/javascript" src="../../../jqwidgets/jqxgrid.selection.js"></script> 
        <script type="text/javascript" src="../../../jqwidgets/jqxgrid.columnsresize.js"></script> 
        <script type="text/javascript" src="../../../jqwidgets/jqxdata.js"></script> 
        <script type="text/javascript" src="../../../scripts/demos.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                var url = "../../sampledata/beverages.txt";
    
                // prepare the data
                var source =
                {
                    datatype: "json",
                    datafields: [
                        { name: 'name', type: 'string' },
                        { name: 'type', type: 'string' },
                        { name: 'calories', type: 'int' },
                        { name: 'totalfat', type: 'string' },
                        { name: 'protein', type: 'string' }
                    ],
                    id: 'id',
                    url: url,
                    addrow: function (rowid, rowdata, position, commit) {
                        // synchronize with the server - send insert command
                        // call commit with parameter true if the synchronization with the server is successful 
                        //and with parameter false if the synchronization failed.
                        // you can pass additional argument to the commit callback which represents the new ID if it is generated from a DB.
                        commit(true);
                    },
                };
                var dataAdapter = new $.jqx.dataAdapter(source);
    
                $("#grid").jqxGrid(
                {
                    width: getWidth('Grid'),
                    source: dataAdapter,
                    columnsresize: true,
                    columns: 
                    [
                      { text: 'Name', datafield: 'name', width: 250 },
                      { text: 'Beverage Type', datafield: 'type', width: 250 },
                      { text: 'Calories', datafield: 'calories', cellsformat: 'd2', width: 180 },
                      { text: 'Total Fat', datafield: 'totalfat', width: 120 },
                      { text: 'Protein', datafield: 'protein', minwidth: 120 }
                  ]
                });
            });
    
            function add()
            {
                var datarow = 
                [
                    { 
                        name :  'abc',
                        type : 'def',
                        calories : '10',
                        totalfat : 'ghi',
                        protein : 'jkl', 
                    }
                ];
    
                $("#grid").jqxGrid('addrow', null, datarow);
            }
        </script>
    </head>
    <body class='default'>
            <div id="grid"></div>
    
    <div style="position: absolute; bottom: 5px; right: 5px;">
    <a href="https://www.jqwidgets.com/" alt="https://www.jqwidgets.com/"><img alt="https://www.jqwidgets.com/" title="https://www.jqwidgets.com/" src="https://www.jqwidgets.com/wp-content/design/i/logo-jqwidgets.png"/></a>
    </div>
    
    <button onclick=add()>Add</button>
    </body>
    </html>
    
    Localdata, addrow & cellsformat problem #107555

    Peter Stoev
    Keymaster

    Please, refer to http://jsfiddle.net/jqwidgets/fZhEc/

    It should help you.

    Regards,
    Peter

    jQWidgets Team
    https://www.jqwidgets.com/

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

You must be logged in to reply to this topic.