prattcmp Posted August 18, 2013 Report Share Posted August 18, 2013 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"); } ); } Quote Link to comment Share on other sites More sharing options...
prattcmp Posted August 22, 2013 Author Report Share Posted August 22, 2013 Is there anyone who can help me with this? Quote Link to comment Share on other sites More sharing options...
prattcmp Posted August 22, 2013 Author Report Share Posted August 22, 2013 I've also found that when I go to the "My Flight Bids" page it doesn't return anything, while I see 3 flights in the SQL db. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.