EasyUI Forum
May 14, 2021, 01:11:17 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: eDatagrid - Pass dynamic parameters & query data base on the parameters  (Read 336 times)
Franky
Newbie
*
Posts: 11


View Profile Email
« on: January 26, 2021, 08:07:32 PM »

Hi Sir,

I'm using editable datagrid extension, having a datagrid which data come from database. However I need to pass parameter(let say userID) to the page so that the datagrid will show different set of data based on login id.

May I know any example to achieve this?

front end code:
dg.edatagrid({
                    //title:'DataGrid - DetailView',
                    width:'auto',
                    height:'auto',
                    remoteSort:false,
                    //singleSelect:true,
                    nowrap:false,
                    fitColumns:true,
                    striped:true,
                    pagination:true,
                    multiSort:true,
                    url:'php/get_coo_data.php',
                    columns:[[
                        {field:'item',title:'Item',width:40,sortable:true},
                        {field:'desc1',title:'Desciption',width:100,sortable:true},
                        {field:'prod_type',title:'Product Type',width:60,align:'center',sortable:true}
                    ]]
})


backend code:
require_once('config.php');
userID = POST['userID'];

$sql = "SELECT * FROM item WHERE user_id = userID ";

$result = mysqli_query($sql);

$data = array();

while($row = mysqli_fetch_assoc($result)){
   $data[]   = $row;
}

echo json_encode($data);



Thanks.
Logged
jarry
Administrator
Hero Member
*****
Posts: 1978


View Profile Email
« Reply #1 on: January 26, 2021, 09:58:53 PM »

When the 'userID' is changed, call the 'load' method with the new parameter values to retrieve data from server.
Code:
dg.edatagrid('load',{
userID: ...
});
Logged
Franky
Newbie
*
Posts: 11


View Profile Email
« Reply #2 on: January 27, 2021, 12:47:40 AM »

Hi Jarry,

Thank you, that's work.

However if I want it to initiate when the page first load, without needed to reload the datagrid, i now use queryParams.


dg.edatagrid({
                    width:'auto',
                    height:'auto',
                    remoteSort:false,
                    nowrap:false,
                    fitColumns:true,
                    striped:true,
                    pagination:true,
                    multiSort:true,
                    url:'php/get_coo_data.php',
                    queryParams:{bpID:login},
                    columns:[[
                        {field:'item',title:'Item',width:40,sortable:true},
                        {field:'desc1',title:'Desciption',width:100,sortable:true},
                    ]]
})
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!