Jump to content

Add/Remove bid in jqGrid


prattcmp

Recommended Posts

I am trying to add a button to my jqgrid schedule that will add and remove a bid from that schedule. I'm not exactly sure how to do it yet. The way it's setup is that I have my jqgrid in schedule_results.tpl. There are two javascript functions. One that does an ajax to add a bid and one that does an ajax to remove a bid. I also have some code in Schedules.php that feeds the information to the grid. Currently, all that I can do is press add in the grid and it will add a bid. I want to make it do when they add a bid, the grid shows remove in that cell and will run the remove function when pressed.

PHP:
public function schedulegrid()
{
$page = $this->get->page; // get the requested page 
$limit = $this->get->rows; // get how many rows we want to have into the grid 
$sidx = $this->get->sidx; // get index row - i.e. user click to sort 
$sord = $this->get->sord; // get the direction 
if(!$sidx) $sidx =1;

# http://dev.phpvms.net/admin/action.php/operations/
# ?_search=true&nd=1270940867171&rows=20&page=1&sidx=flightnum&sord=asc&searchField=code&searchString=TAY&searchOper=eq

/* Do the search using jqGrid */
$where = array();
if($this->get->_search == 'true') 
{
$searchstr = jqgrid::strip($this->get->filters);
$where_string = jqgrid::constructWhere($searchstr);

# Append to our search, add 1=1 since it comes with AND
# from above
$where[] = "1=1 {$where_string}";
}

Config::Set('SCHEDULES_ORDER_BY', "{$sidx} {$sord}");

# Do a search without the limits so we can find how many records
$count = SchedulesData::countSchedules($where);
$bids = SchedulesData::getBids(Auth::$userinfo->pilotid);
print_r($bids);
if($count > 0) 
{
$total_pages = ceil($count/$limit);
} 
else 
{
$total_pages = 0;
}

       if ($page > $total_pages) 
       {
$page = $total_pages;
}

$start = $limit * $page - $limit; // do not put $limit*($page - 1)
if ($start < 0) 
{
$start = 0;
}

# And finally do a search with the limits
$schedules = SchedulesData::findSchedules($where, $limit, $start);
if(!$schedules)
{
$schedules = array();
}

# Form the json header
$json = array(
'page' => $page,
'total' => $total_pages,
'records' => $count,
'rows' => array()
);

# Add each row to the above array
foreach($schedules as $row)
{
if($row->route != '')
{
$route = '<a href="#" onclick="showroute(\''.$row->id.'\'); return false;">View</a>';
}
else
{
$route = 'None';
}

$bid = $row->bidid;

if($bid != 0)
{

}

$tmp = array(
'id' => $row->id,
'cell' => array(
# Each column, in order
$row->code,
$row->flightnum,
$row->depicao,
$row->arricao,
$row->aircraft,
$row->distance,
$route,
$bid,
),
);

$json['rows'][] = $tmp;
}

header("Content-type: text/x-json");
echo json_encode($json); 
}

Javascript:

function addbid(id)
{
$.post("http://virtualunited.net/action.php/schedules/addbid", { id: id },
function() 
{ 
$("#grid").trigger("reloadGrid"); 
}
);
}

function removebid(id)
{
$.post("http://virtualunited.net/action.php/schedules/removebid", { id: id },
function() 
{ 
$("#grid").trigger("reloadGrid"); 
}
);

}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...