Does anyone have an example of using the QSortable toArray function. I have been experimenting with it to get the Items Array and I keep getting a null result.
I am doing that manualy bacause we are still on 1.x (sorting datagrid)
JS in template
<script type="text/javascript"> function get_data() { var a=$("#<?php echo $this->dtgLvl0->ControlId?>").sortable("serialize"); $("#<?php echo $this->lblLvl0->ControlId?>").val(a); }; function bindlvl() { $("#<?php echo $this->dtgLvl0->ControlId?>").sortable({ items: 'tbody > tr',cursor: 'move' }); $("#<?php echo $this->dtgLvl0->ControlId?>").disableSelection(); };
PHP
$this->lblLvl0 = new QTextBox($this);
$this->btn0Save = new Qbutton($this); $this->btn0Save->Text='SaveChanges'; $this->btn0Save->AddAction(new QClickEvent(), new QJavaScriptAction('get_data()')); $this->btn0Save->AddAction(new QClickEvent(), new QAjaxAction('btn0Save_Click'));
public function btn0Save_Click($strFormId, $strControlId, $strParameter){ $counter0=0; $str=str_replace('row', '', $this->lblLvl0->Text); $str=str_replace($this->dtgLvl0->ControlId, 'sorting_list', $str); parse_str($str);//Convert Txt to Array $sorting_list $new_list=Array(); foreach($sorting_list as $v){ $new_list[]=$this->objLvl0Array[$v]; } foreach ($new_list as $MenuItem){ $MenuItem->SortId=$counter0; $MenuItem->Save(); $counter0++; } }
Explanation
$this->objLvl0Array is array for datagrid containing menu items to sort
$this->lblLvl0 = new QTextBox($this); is used to get data back from JS and that part is missing in QSortable class
Serialize() and ToArray() functions are not finished, they are missing input feald to return data.
public function ToArray() {
$args = array();
$args[] = "toArray";
$strArgs = JavaScriptHelper::toJson($args);
$strJs = sprintf('jQuery("#%s").sortable(%s)',
$this->getJqControlId(),
substr($strArgs, 1, strlen($strArgs)-2));
QApplication::ExecuteJavaScript($strJs);
}
I am doing that manualy bacause we are still on 1.x (sorting datagrid)
JS in template
<script type="text/javascript">function get_data() {
var a=$("#<?php echo $this->dtgLvl0->ControlId?>").sortable("serialize");
$("#<?php echo $this->lblLvl0->ControlId?>").val(a);
};
function bindlvl() {
$("#<?php echo $this->dtgLvl0->ControlId?>").sortable({
items: 'tbody > tr',cursor: 'move'
});
$("#<?php echo $this->dtgLvl0->ControlId?>").disableSelection();
};
PHP
$this->lblLvl0 = new QTextBox($this);
$this->btn0Save = new Qbutton($this);
$this->btn0Save->Text='SaveChanges';
$this->btn0Save->AddAction(new QClickEvent(), new QJavaScriptAction('get_data()'));
$this->btn0Save->AddAction(new QClickEvent(), new QAjaxAction('btn0Save_Click'));
public function btn0Save_Click($strFormId, $strControlId, $strParameter){
$counter0=0;
$str=str_replace('row', '', $this->lblLvl0->Text);
$str=str_replace($this->dtgLvl0->ControlId, 'sorting_list', $str);
parse_str($str);//Convert Txt to Array $sorting_list
$new_list=Array();
foreach($sorting_list as $v){
$new_list[]=$this->objLvl0Array[$v];
}
foreach ($new_list as $MenuItem){
$MenuItem->SortId=$counter0;
$MenuItem->Save();
$counter0++;
}
}
Explanation
$this->objLvl0Array is array for datagrid containing menu items to sort
$this->lblLvl0 = new QTextBox($this); is used to get data back from JS and that part is missing in QSortable class