Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 10 Next »

Sets the URL to a server-side script that returns the data for a database-driven grid. The server-side logic can be written with Profound UI's Universal Displays or any other web development framework. The script will receive parameters "start" and "limit" in the HTTP POST data to, which tell which records in the set are to be returned. The script is called repeatedly as the user scrolls through the gird so that only one page of records is returned by the server at one time. The output is a record set in JSON format, see the examples below. On the first request to the server-side script an additional parameter "getTotal=1" is passed. When this is present, the script must return the total number of records in the set using the "totalRecs" property in the output.

Promptable? YES
Possible Values: Any valid URL
Bindable? YES
Products: ProfoundUI, Genie

Example: Succes
{
    "success": true,
    "response": {
        "results": [
            {
                "PNAME": "QUEST BOREAL",
                "PRID": "523"
            },
            {
                "PNAME": "QUEST ECLIPSE",
                "PRID": "524"
            },
            {
                "PNAME": "QUEST EQUINOX",
                "PRID": "525"
            }
        ],
        "totalRecs": 6 // Two pages, three records per page.
    }
}
Example: Failure
{
    "success": false,
    "errorId": "08001",
    "errorText": "My error message."
}

 

PHP Example

This example assumes your installation has PHP enabled. Setup a grid in a Rich Display File or Genie screen with the following properties:

  • has header: true
  • column headings: PRID,PRNAME
  • number of rows: 7
  • number of columns: 2
  • scrollbar: sliding
  • data url: /mydataurlexample.php

Note that the header row counts as one row, so when "number of rows" is 7, there are actually 6 rows of data.

Place the following PHP code into a file named by the "data url" in the grid; e.g. /www/profoundui/htdocs/mydataurlexample.php.

mydataurlexample.php
<?php
/*
Simple web service to supply a grid "data url" property.
Profound Logic Software. 2016.
*/
header('Content-Type: text/json');

// Response is bad until proven otherwise.
$response = array("success" => false);

// Setup some sample data.
$data = array();
$data[] = array("PRID" => 9, "PNAME" => "NALGENE 16 OZ WIDE-MOUTH LEXAN");
$data[] = array("PRID" => 10, "PNAME" => "NALGENE 32 OZ WIDE-MOUTH LEXAN");
$data[] = array("PRID" => 11, "PNAME" => "NALGENE WIDE MOUTH LOOP-TOP BO");
$data[] = array("PRID" => 13, "PNAME" => "MOTOROLA PEANUT RADIO MODEL T6");
$data[] = array("PRID" => 14, "PNAME" => "MOTOROLA PEANUT RADIO MODEL T6");
$data[] = array("PRID" => 15, "PNAME" => "MOTOROLA PEANUT RADIO MODEL T6");
$data[] = array("PRID" => 17, "PNAME" => "SUN SHOWER ENCLOSURE");
$data[] = array("PRID" => 18, "PNAME" => "NALGENE 16 OZ NARROW-MOUTH LEX");
$data[] = array("PRID" => 19, "PNAME" => "NALGENE 32 OZ NARROW-MOUTH LEX");
$data[] = array("PRID" => 23, "PNAME" => "POLYPRO UNDERWEAR BOTTOMS");
$data[] = array("PRID" => 24, "PNAME" => "PRINCETON TEC SPORT FLARE");
$data[] = array("PRID" => 25, "PNAME" => "PRINCETON TEC SOLO");
$data[] = array("PRID" => 26, "PNAME" => "PRINCETON TEC VORTEC");
$data[] = array("PRID" => 27, "PNAME" => "PRINCETON TEC TEC20");

// The request is valid: "start" and "limit" are at least 1.
if( isset($_POST["limit"]) && isset($_POST["start"]) && (int)$_POST["limit"] > 0 && (int)$_POST["start"] > 0 ){
    $response["success"] = true;
    $response["response"] = array("results" => array());
    
    // The grid sends us "getTotal" on the first request. If this is the first request, we respond with the number of records.
    if( isset($_POST["getTotal"]) && (int)$_POST["getTotal"] == 1 ){
        $response["response"]["totalRecs"] = 14;
    }
    
    // Decide which section of data to read, and append data to response.
    $idx = $_POST["start"] - 1;    //PHP array index begins at 0, but POST["start"] starts at 1.
    $maxrow = min( $idx + $_POST["limit"], count($data));
    while( $idx < $maxrow ){
        $response["response"]["results"][] = $data[$idx];
        $idx++;
    }
}//end if request valid.
else
{
    $response["errorId"] = "00001";
    $response["errorText"] = "Invalid start or limit parameters.";
}
echo json_encode($response, JSON_PRETTY_PRINT );
?>

That's all:

Note, each time you scroll to a new starting row, the client browser requests a new page from the server-side script. If the parameters do not change, then the client caches responses.

  • No labels