EasyUI Forum
September 16, 2025, 11:21:46 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: How do I load a PropertyGrid?  (Read 11678 times)
tenly
Newbie
*
Posts: 7


View Profile
« on: July 16, 2015, 10:15:57 PM »

Hi All,

I'm new to jquery, php, easyui and html and I've been stumped on something I think should be pretty basic for a month now.

I'll try to make my problem as simple as possible.

I have an html document which contains a textbox, 2 buttons (load and refresh) and an empty div element.
A user is meant to enter a server name into the textbox and then click the button.

The load button should:
- run a function (ajax) which retrieves a list of services and the current status of each service.
- create a property grid populated with the service name/service status.

The refresh button should:
- re-run the query and update the data in the property grid

I have a powershell script on the web-server which can collect the required data.
I can have the powershell script return the data formatted in whatever way is required - but I need someone to tell me what format to use!

So far most of my testing has involved trying to generate the output from powershell in json format and using PHP to invoke the powershell script and return it to the html.
But no matter what I do, I can't get the PropertyGrid control to use it as a datasource.  I've tried using both the "url" and the "data" parameters with no luck.

So - can someone please help me?  How can I use PowerShell to generate the data I want to display in a PropertyGrid???

Thanks in advance to any that reply...
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: July 16, 2015, 11:15:25 PM »

Please refer to this example http://www.jeasyui.com/demo/main/index.php?plugin=PropertyGrid&theme=default&dir=ltr&pitem=Basic.

The data to be loaded looks like this:
Code:
{"total":7,"rows":[
{"name":"Name","value":"Bill Smith","group":"ID Settings","editor":"text"},
{"name":"Address","value":"","group":"ID Settings","editor":"text"},
{"name":"Age","value":"40","group":"ID Settings","editor":"numberbox"},
{"name":"Birthday","value":"01/02/2012","group":"ID Settings","editor":"datebox"},
{"name":"SSN","value":"123-456-7890","group":"ID Settings","editor":"text"},
{"name":"Email","value":"bill@gmail.com","group":"Marketing Settings","editor":{
"type":"validatebox",
"options":{
"validType":"email"
}
}},
{"name":"FrequentBuyer","value":"false","group":"Marketing Settings","editor":{
"type":"checkbox",
"options":{
"on":true,
"off":false
}
}}
]}
Logged
tenly
Newbie
*
Posts: 7


View Profile
« Reply #2 on: July 17, 2015, 08:06:49 AM »


Thanks for the reply stworthy.  Of course, I'd seen the demo and tried every possible variation of it I could think of - with and without the square brackets, trying to set the returned data into a javascript variable and then use the 'data' parameter to populate the property grid, etc and none of them worked.  The behavior I was consistently seeing was that if I saved the results to a file called returndata.json and then served up that file to the URL parameter, it would work - but if i set the url to returndata.php, it would fail - and when I opened the .php file in a browser directly and did a view source - the data displayed *exactly* matched the data in the .json file (right down to crlf characters and encoding).  I

However - since you took the time to reply to my question, I decided to humor you and rebuild my test using your example from the documentation so I could tell you exactly where it was failing...except this time it didn't fail....Huh  ARGH!!!  I've spent a month on this problem and it turns out the documentation was right all along?  I'm guessing that in my earlier testing, there must have been a PHP error or info message that was invisibly getting in the way?

In any case - thanks very much for your reply and for setting me straight.  None of the examples actually showed how to generate the json data via code so I wasn't completely sure I was generating it in the correct format. I thought I might need one extra set (or one fewer set) of quotes, curly brackets or square brackets - or some special html tag to surround the data - but now that I've finally seen it work, I'll be able to move forward.  I was having a similar issue with several datagrid controls and I'm sure I will also be able to move forward with them now too!

Thanks again for taking the time to respond to such a simple question!

Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: July 17, 2015, 11:16:48 PM »

Make sure to return the correct json data from your server. The code below shows how to return the propertygrid data using PHP script.
Code:
<?php

$rows 
= array();
$rows[] = array(
"name" => "Name",
"value" => "name1",
"editor" => "textbox"
);
$rows[] = array(
"name" => "Email",
"editor" => array(
"type" => "validatebox",
"options" => array(
"validType" => "email"
)
)
);
echo 
json_encode($rows);

?>

Logged
tenly
Newbie
*
Posts: 7


View Profile
« Reply #4 on: July 18, 2015, 06:57:15 PM »

Thanks Stworthy,

Thanks for your reply with additional tips!

I found out that one of my main problems initially was that some of the values I was returning contained illegal characters that needed to be escaped.  Once I fixed that up, it started working as I expected it to.

The way I've been handling passing the data (so far) is to have the powershell script generate the output in json-like format (using an echo) and then having PHP simply pass it back to the HTML as-is:

Powershell:
Code:
  $infile = get-content c:\inis\myinputfile.ini
  $outfile = "["
  $count = 0
  $comma = ","
  $infile|foreach {
    $count = $count + 1
    $inline = ($_).split("=")
    $name=$inline[0];$value=($inline[1]).replace("\","\\")
    if ($infile.length -eq $count) {$comma = ""}
    $outfile = "$($outfile)`r`n{`"name`":`"$name`",`"value`":`"$value`",`"group`":`"$groupname`"}$comma"
  }
  $outfile = "$($outfile)]"
  $outfile|foreach {echo "$_`r`n"}

PHP:
Code:
<?php
  $username 
$_SERVER["PHP_AUTH_USER"];
  
$custname=$_GET["custname"];
  
$propfile=$_GET["propfile"]; 
  
$tmp system("powershell -executionpolicy bypass d:/scripts/ps/supportkit.ps1 getproperties $username $custname $propfile",$err);
?>


Is there anything inherently wrong with this approach (besides the ugly-looking echo statement)?  Or some compelling reason to use the mechanism you provided instead of sticking with my current model?  (I'm much more comfortable working in Powershell than I am in PHP or JavaScript).

Thanks in advance for any advice you care to share!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!