Option Type P (pos) - $nextpos

When we are using positioning for every row inserted we need to keep all of these into consideration.

When using positioning in a table view, we need to add the option type "p" to the table view but also to the Add Form so it can respect the sequence already created. (not the update form)

 

$HOME->setOption("ADD BANNER,AGREGAR BANER,AJOUTER BANIER","aside","4","FAPS");
$HOME->setOption("VIEW BANNERS,VER BANERS,VOIR ANIERS","aside","4","VIPLDSE",true);
 
 
This is very straight forward but unless we specify the next position, by default KAS will assign position 0 to the new row, so in our Form View (Add) we will add a query to determine the next position:
 
For the first position we can add:
 
 
$nextpos = 'first';  //This is the default
 
 
For the last position:
 
 
$nextpos = 'last';
 
 
Or we can specify a specific position:
 
 
$count = $connection->new_query("SELECT COUNT($idfield) as next FROM  $dbtable", $kas['debugMode']);
$nextpos = $count->result(0,'next');

 

On the View Table page, by default is the option type P is added, it will automatically add the drag icons to change the row's position, and it will use the variable "pos" as the column name in the database.

If we want to order by a different column we need to add the variable $orderby and of the value is not "pos" it will not show the arrows on each row

$orderby = 'pos';

If we need to order by a different database column and allow the the tabke to modify the position based on a database column that is not "pos", we need to add a variable $posCol, then change the value of $orderby and tell KAS to always show positioning with $showpos

$posCol = 'new_pos';
$orderby = $posCol;
$showpos = true;
We can combine this feature with the sort option of the columns, but we need to add a few conditionals and modify our query:
 
$posCol = 'new_pos';

if(!isset($ob)){
    $orderby = $posCol;
    $asde = 'DESC';
    $showpos = true;
}else{
    $orderby = $ob;
    $showpos = false;
}

$query = "SELECT *  FROM $dbtable %%WHERE%% order by $orderby $asde";

 

 

 
 
 
Get a Quote

Get a Quote