jQWidgets Forums

jQuery UI Widgets Forums Grid no data to display

This topic contains 2 replies, has 2 voices, and was last updated by  oreoisgood 9 years ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • no data to display #82579

    oreoisgood
    Participant

    i use my php could show the data for my php
    http://orecen.esy.es/fypv4/bdata/test.php

    
    <?php
    	$firstNames = array("Andrew", "Nancy", "Shelley", "Regina", "Yoshi", "Antoni", "Mayumi", "Ian","Peter", "Lars", "Petra", "Martin", "Sven", "Elio", "Beate", "Cheryl", "Michael", "Guylene");
    
    	$lastNames = array("Fuller", "Davolio", "Burke", "Murphy", "Nagase", "Saavedra", "Ohno", "Devling","Wilson", "Peterson", "Winkler", "Bein", "Petersen", "Rossi", "Vileid", "Saylor", "Bjorn", "Nodier");
    
    	$productNames = array("Black Tea", "Green Tea", "Caffe Espresso", "Doubleshot Espresso", "Caffe Latte", "White Chocolate Mocha", "Cramel Latte", "Caffe Americano", "Cappuccino", "Espresso Truffle", "Espressocon Panna", "Peppermint Mocha Twist", "Black Tea", "Green Tea", "Caffe Espresso", "Doubleshot Espresso", "Caffe Latte", "White Chocolate Mocha");
    
    	$priceValues = array("2.25", "1.5", "3.0", "3.3", "4.5", "3.6", "3.8", "2.5", "5.0","1.75","3.25","4.0", "2.25", "1.5", "3.0", "3.3", "4.5", "3.6");
    
    	$data = array();
    	$i=0;
    	while($i < count($productNames))
    	{    
    	  $row = array();
    	  $productindex = $i;
    	  $price = $priceValues[$productindex];
    	  $quantity = rand(1, 10);
    	  $row["countryName"] = $firstNames[$i];
    	  $row["lastname"] = $lastNames[$i];
    	  $row["productname"] = $productNames[$productindex];
    	  $row["price"] = $price;
    	  $row["quantity"] = $quantity;
    	  $row["total"] = $price * $quantity;
    
    	  $data[$i] = $row;
    	  $i++;
    	}
    	 
            header('Access-Control-Allow-Origin: *');
          
    	header("Content-type: application/json"); 
    	echo "{\"data\":" .json_encode($data). "}";
    ?>
    

    html:

    
    <script type="text/javascript">
            $(document).ready(function () {
                // prepare the data
                var source =
                {
                    datatype: "jsonp",
                    datafields: [
                        { name: 'countryName' , type:'string' },
                        { name: 'adminCode1' },
                        { name: 'productname'},
                        { name: 'ROUTE_ID', type: 'int' },
                        { name: 'price', type: 'float' },
                        { name: 'total', type: 'float' }
                    ],
                    url: "http://orecen.esy.es/fypv4/bdata/test.php"
                    //url : "http://api.geonames.org/searchJSON?username=jqwidgets"
                };
                var dataAdapter = new $.jqx.dataAdapter(source);
    
                $("#jqxgrid").jqxGrid(
                {
                    width: 850,
                    source: dataAdapter,
                    columnsresize: true,
                    columns: [
                        { text: 'Company Name', datafield: 'countryName', width: 250 },
                        { text: 'Contact Name', datafield: 'adminCode1', width: 150 },
                        { text: 'Contact Title', datafield: 'ContactTitle', width: 180 },
                        { text: 'City', datafield: 'City', width: 120 },
                        { text: 'Country', datafield: 'Country'}
                    ]
                });
            });
        </script>
    </head>
    <body class='default'>
        <div id='jqxWidget'>
            <div id="jqxgrid"></div>
        </div>
    </body>
    
    no data to display #82584

    ivailo
    Participant

    Hi oreoisgood,

    You are using datatype: "jsonp", but your data is in json format, so better use datatype: "json",.
    Also there is a minimal relation between your source data, data fields and columns.
    Only countryName field exist in both places, so only the column with it’s content will be filled. All other columns will be with an empty fields.

    To have a correct filled grid use data fields with names relevant to the data, returned from your url.

    Best Regards,
    Ivailo Ivanov

    jQWidgets Team
    http://www.jqwidgets.com

    no data to display #82586

    oreoisgood
    Participant

    thank you ,It is work for me

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

You must be logged in to reply to this topic.