EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: kavvson on October 14, 2014, 07:23:53 AM



Title: [Solved] Changing the datagrid url based on input radio selection
Post by: kavvson on October 14, 2014, 07:23:53 AM
Code:
<div class="adv_filter">
<li>
<input type="radio" name="letter_type" data-custom="Option1" value="0">  Option1
</li><li>
<input type="radio" name="letter_type" data-custom="Option2" value="1" checked="checked">  Option2
</li><li>
<input type="radio" name="letter_type" data-custom="Option3" value="2">  Option3
</li>  
</div>

var url = 'lists.php?ltype='+input_radio_value;

Code:
		$("li").on("click", "input", function() {
$('#dg').datagrid('reload');
// add = $(this).text().val();
globalVar = 'lists.php?ltype='+$(this).val();
});
This onclick function gets the Option1 name only, but I want to get the value thats the first thing. The second this is to override the url with the ?=ltype value, is this even possible? I got in my lists.php $_GET for ltype and everything properly configurated, manually inserting the value works but I want to be able to do it when I select a radio . But basically I have no idea how to accomplish this.

How to get the globalVar isnide

Code:
$('#dg').datagrid({
url : url,


SOLVED AT : http://stackoverflow.com/questions/26387676/passing-a-variable-into-an-other-function-jeasyui


Title: Re: Changing the datagrid url based on input radio selection
Post by: chrwei on October 14, 2014, 07:58:52 AM
first problem is that "this" is not going to be the input, off the top of my head you can get that via $("input[name='letter_type']:selected"), or maybe :checked, but that's just jquery stuff.   

then, instead of having the params in the url, define the grid like:

Code:
$('#dg').datagrid({
url: 'lists.php',
queryParams: {
ltype: 'default'
}
});

if you don't want a default then make lists.php return an empty set.  then you can use the 'load' method to change the queryParams and load the new data


Title: Re: Changing the datagrid url based on input radio selection
Post by: kavvson on October 14, 2014, 08:06:18 AM
It sounds logical, but I cant move on I don't know how to do that:(


Title: Re: Changing the datagrid url based on input radio selection
Post by: chrwei on October 14, 2014, 11:15:49 AM
it's in the documentation http://www.jeasyui.com/documentation/index.php# under "Query data with some parameters."



Title: Re: Changing the datagrid url based on input radio selection
Post by: kavvson on October 14, 2014, 11:24:35 AM
Code:
$("li").on("click", "input", function() {
$('#dg').datagrid('reload');
// add = $(this).text().val();
globalVar = $(this).val();
});

$('#dg').datagrid({
url: 'lists.php',
queryParams: {
ltype: globalVar
}
});

Ok but can you tell me how to pass the globalVal to query param? And wont it be static? When I press the checkboxe's will it reload the grid - supposingly no.


Title: Re: Changing the datagrid url based on input radio selection
Post by: chrwei on October 14, 2014, 11:29:43 AM
did you look at the docs on the load method?  you don't need reload at all.  reload fetches updated data using the same parameters.


Title: Re: Changing the datagrid url based on input radio selection
Post by: kavvson on October 14, 2014, 11:47:07 AM
The link doesn't refere to that. Its index, and there is no under " ". Could you show a example then?


Title: Re: Changing the datagrid url based on input radio selection
Post by: chrwei on October 14, 2014, 11:59:43 AM
right from the docs:
Code:
$('#dg').datagrid({
    url:'file.php',
    columns:[[
        {field:'code',title:'Code',width:100},
        {field:'name',title:'Name',width:100},
        {field:'price',title:'Price',width:100,align:'right'}
    ]]
});

$('#dg').datagrid('load', {
    name: 'easyui',
    address: 'ho'
});



Title: Re: Changing the datagrid url based on input radio selection
Post by: kavvson on October 14, 2014, 12:26:40 PM
that's not what I am looking after also;/


Title: Re: Changing the datagrid url based on input radio selection
Post by: chrwei on October 14, 2014, 12:35:31 PM
in this case the 'load' call sends name and address query parameters to file.php and reloads the grid data.  it's exactly what you asked for.  sub in your values.


Title: Re: Changing the datagrid url based on input radio selection
Post by: kavvson on October 15, 2014, 03:31:52 AM

Code:
name: 'easyui',
address: 'ho'

what variables does it take / stands for ( name, address ) cause the default values doesn't tell me anything.. ho ? easyui is the grid id?


Title: Re: Changing the datagrid url based on input radio selection
Post by: chrwei on October 15, 2014, 07:11:37 AM
no, it's just a text string.  is this more clear?

Code:
$('#dg').datagrid('load', {
    some_param: 'a value',
    another_param: 'another value'
});