EasyUI Forum
May 03, 2024, 08:06:49 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Select value in JSON  (Read 36001 times)
ClSoft
Jr. Member
**
Posts: 92


View Profile
« on: February 11, 2013, 10:58:33 AM »

Hi all
I saw that is possible to pre-select value in the JSON file - in the combobox - using "selected":true
http://www.jeasyui.com/documentation/combobox.php

is that also possible in the combogrid, using JSON?
I'm loading data into combogrid, using JSON file, and I need to pre-select value.
Thanks.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: February 11, 2013, 11:49:14 AM »

The value property can be used to select a specified row. See this example http://www.jeasyui.com/demo/main/index.php?plugin=ComboGrid&theme=default&dir=ltr&pitem=Initialize%20Value%20for%20ComboGrid
Logged
ClSoft
Jr. Member
**
Posts: 92


View Profile
« Reply #2 on: February 11, 2013, 03:09:17 PM »

Hi
yes, I saw that but I meant that it is possible to put such values into JSON file (because I need to create it).
Now I need to design HTML - something like value="xxx" and replace "xxx" with real value, but it is OK when I know what I need to do Smiley
Thanks.
Logged
ClSoft
Jr. Member
**
Posts: 92


View Profile
« Reply #3 on: February 12, 2013, 02:46:42 PM »

Hmmm ...
I have problem with value="initialValue"
Problem is - I need to set that value "on the fly",just before opening that page, and I'm not sure how to do that.
Now I have some grid and window declared on same page. on that window, I have ComboGrid which uses JSON data.
This window is initially closed.
On some button Click, I open that window and need to pre-select value on grid. Problem is - page is loaded and I can not replace me "initialValue".
I can do that but then I need to reload whole page, and that is not good option.
Best option for me is to use preselected value in the JSON data, like it is possible in the ComboTree or ComboBox.
Any idea?
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #4 on: February 12, 2013, 06:04:07 PM »

A solution to solve this issue is to find the row to be selected and call 'setValue' method when loaded data successfully. The code below demonstrate how to do this.
Code:
	<select class="easyui-combogrid" style="width:250px" data-options="
panelWidth: 500,
idField: 'itemid',
textField: 'productname',
url: '../combogrid/datagrid_data1.json',
columns: [[
{field:'itemid',title:'Item ID',width:80},
{field:'productname',title:'Product',width:120},
{field:'listprice',title:'List Price',width:80,align:'right'},
{field:'unitcost',title:'Unit Cost',width:80,align:'right'},
{field:'attr1',title:'Attribute',width:200},
{field:'status',title:'Status',width:60,align:'center'}
]],
fitColumns: true,
onLoadSuccess: function(data){
var rows = data.rows;
for(var i=0; i<rows.length; i++){
var row = rows[i];
if (row.selected){  // the row with 'selected' property set to true will be acted as the selected row
$(this).combogrid('setValue',row.itemid);
}
}
}
">
</select>
Logged
ClSoft
Jr. Member
**
Posts: 92


View Profile
« Reply #5 on: February 13, 2013, 12:09:12 AM »

Thanks man, but I don't know how to select row?
This is what I do:
I catch GET data and take "/combogrid/datagrid_data1.json" and fill it with my data.
It is done on server RequestDone event (I'm using my software as Webserver)
With other words, I know when this line is executed:
"url: '../combogrid/datagrid_data1.json"
and I send to client current data inside JSON file .. huhhh... it is pretty unclear, I know..
In that moment, I know what row should be selected, but I don't know hot to "tell" that to combogrid?

This is what I send :
{"total":3,"rows":[
   {"group_id":"1","group_name":"Koi1"},
   {"group_id":"2","group_name":"Koi2"},
   {"group_id":"3","group_name":"Koi3"}
]}

and if I know that second row is the right one, how to send that to combogrid?
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #6 on: February 13, 2013, 05:58:49 AM »

Add selected property to what row you want to select.
Code:
{"group_id":2,"group_name":"koi2","selected":true}
Logged
ClSoft
Jr. Member
**
Posts: 92


View Profile
« Reply #7 on: February 13, 2013, 11:55:43 AM »

Arrghhh...
it should work, but it doesn't.
The reason is - your example code (below) is in single page, on window which is initially closed:

if (row.selected){  // the row with 'selected' property set to true will be acted as the selected row
   $(this).combogrid('setValue',row.itemid);
}

It is executed once, when whole page is loaded.
Now I need to move this dialog to new page and then it should work - but then I have another question:
any example app where I can see how to call dialog on other page?
I can create new page, like mydialog.html and copy code inside it, but how to call that page from "main" page, and how to return to original page??
Logged
mzeddd
Full Member
***
Posts: 223



View Profile
« Reply #8 on: February 13, 2013, 12:21:48 PM »

Initial question was very clear for me as well as answer from stworthy.

But now I don't really see the problem or what you are going to archive.

If you have combo element in one page and you would like to process data from this page on the other page you can:
- store this data into cookie
- store this data into session
- GET/POST this data directly into that page.
- move content from "other" page into "this" page and present it as dialog window which is closed by default.
Logged
ClSoft
Jr. Member
**
Posts: 92


View Profile
« Reply #9 on: February 13, 2013, 02:03:40 PM »

Hi
yes, I'm lost.
Now I'm in the phase that I can not explain the problem Sad and I feel it is so simple but I'm total newbie in web stuff.
OK here is what I try to do:
I have treegrid and some data inside.
Now I have button - change record - and when I press I need to change selected record.
here is Javascript which I use to change record:
Code:
 function changeMember()
  {
    current = $('#members_tree').treegrid('getSelected').id;
    if (current){ 
      $.post("/json/member.json",
      {
        change_member_id:current,
      });
      $('#dlg').dialog('open').dialog('setTitle','Edit Member'); 
      $('#form_member').form('load', '/json/member.json');
    }     
  }

using this :         change_member_id:current,
I know where I am (on which record) in my software and I prepare JSON file (member.json) and send it back to opened dialog, using "Body" ...
OK that part works great.
Now, on opened dialog, I have few comboGrid's.
I meant, I can fill them easy using JSON file, but it does not work, because whole dialog is stored on same page as previous described grid and dialog and everything... dialog is closed, so when I call it .dialog('open') i need somehow to select right value on all combogrid's - but I can not because they are loaded already..
With other words, I need to dynamically select values on combogrid when user click on some row, but I need to get value in JSON because I do that in my software which fill the JSON file (I can not do that using JavaScript because I don't know hot to access database etc.

is it possible to fill combogrid with only one record (for example, if member belongs to "Consultants" group I can fill combogrid only with "Consultants" word and ID, and when user click on combogrid, I can catch "onShowPanel" event and fill other values?
Or any other idea?

Your answer regarding cookie and GET/POST I can not even try, because I have no idea how to use the cookie and GET/POST so maybe for few months but not now Sad
Logged
ClSoft
Jr. Member
**
Posts: 92


View Profile
« Reply #10 on: February 13, 2013, 03:39:02 PM »

OK I found that filling combogrid will not work with my "body" method.
With other words, I can send this (in "body" way) to form:

{
   "firstlastname":"easyui",
   "email":"easyui@gmail.com",
   "phone":"123454321",
   "cell":"3333"
}

and it fill the form fields.

my combogrid JSON looks like this:
{"total":3,"rows":[
   {"group_id":1,"group_name":"Koi1"},
   {"group_id":2,"group_name":"Koi2","selected":true},
        {"group_id":3,"group_name":"Koi3"}
]}

but it will not add or update combogrid on same way.
When I declare combogrid like this:
class="easyui-validatebox"
instead of
class="easyui-combogrid"
then it works, I mean, value is added to entry, but of course, it is not combogrid any more, it is entry field.
Is it possible to fill combogrid like entry?
If yes, I can use events (when user click on arrow) and fill other data.
I just need to see initial value in combogid, when user click on change record.
thanks!
« Last Edit: February 14, 2013, 05:45:14 AM by Clarion » Logged
ClSoft
Jr. Member
**
Posts: 92


View Profile
« Reply #11 on: February 14, 2013, 03:10:49 PM »

I created some hidden input fileds and filled it with values from database, using form('load','myJson.Json')
Then I uset technique as mentioned here:

if (row.selected){  // the row with 'selected' property set to true will be acted as the selected row
   $(this).combogrid('setValue',row.itemid);
}

but also some ChangeEvent (when dialog is opened) where I used .combogrid('setValue',myHiddenField);
on that way I have "transfered" value from database to Json, and then to field, and then to combogrid..
Now it works for 4 combogrid's and thank you all and sorry if I asked dumb questions Sad
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!