Select cell not working after ajax loaded new datas from server

Select cell not working after ajax loaded new datas from server

urbanjurbanj Posts: 20Questions: 4Answers: 0

Dear Allan!
I want to search data in datatables (not filter, or search), and select cell when I found data, and scroll to selcted cell.
Its woking when ajax not loaded new block from server.
Can You tell me what event run when data loaded, and can you test this problem?

You can test this:
log my test system, and type in Keresés cell qqqq and press right arrow on screen.
The select found qqqq in cell and will selkect, and scroll to cell.
Press right arrow key on screen again, the ajax runing and after process endig, the cell not select.
Press right arrow key on screen again, the ajax not runing and the founded cell selected.

You can test:
http://infoportal-hu.ddns.net:62080/index.php?module=TablePage&ID=25
You can login:
email:allandatatables@gmail.com
Jelszó:
AllanDatatables
If you logged in jump again http://infoportal-hu.ddns.net:62080/index.php?module=TablePage&ID=25

Thanks:
Gyula

Replies

  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin

    I don't immediately see anything obvious. Could you tell me where the code is that does the Ajax reload?

    Thanks,
    Allan

  • urbanjurbanj Posts: 20Questions: 4Answers: 0

    Dear Allan!

    This is the LoadData function: (mysql 8 JSON data field)

    private function LoadData()
        {
            $user = User::instance('System::User');
            $db  = DBConnection::instance();
            $tableName=mysqli_real_escape_string($db->getHandler(),$_REQUEST["tableName"]);
            $lastStart=mysqli_real_escape_string($db->getHandler(),$_REQUEST["laststart"]);
            $lastLength=mysqli_real_escape_string($db->getHandler(),$_REQUEST["lastlength"]);
            $ID=mysqli_real_escape_string($db->getHandler(),$_REQUEST["ID"]);
    
            $darabSql="SELECT JSON_LENGTH(fieldsData,'$.Rows') AS darab,tableId 
                    FROM $tableName 
                    WHERE $tableName.ID=$ID";
            $darabRes=$db->query($darabSql);
            
            if(isset($_REQUEST["start"]) && isset($_REQUEST["length"]) && !isset($_REQUEST["action"]))
            {
                $c=0;
                $hossz=mysqli_real_escape_string($db->getHandler(),$_REQUEST["length"]); //length from datatables
                if($hossz==-1)
                {
                    $darabRes[0]["darab"];
                }   
                $start= intval(mysqli_real_escape_string($db->getHandler(),$_REQUEST["start"])); //strat from datatables
                $end=$start+$hossz;
    
                $selSql="SELECT JSON_EXTRACT(fieldsData,'$.Rows[".($start)." to $end]') AS eredmeny, JSON_LENGTH(fieldsData,'$.Rows') AS darab,JSON_EXTRACT(fieldsData,'$.Header') AS header,  tableId 
                    FROM $tableName 
                    WHERE $tableName.ID=$ID";
                $selRes=$db->query($selSql);
                $result= json_decode($selRes[0]["eredmeny"],TRUE);
                if(count($result)<1)
                {
                    $v=json_encode(["data"=>[]]);
                } 
    
                $header= json_decode($selRes[0]["header"],TRUE);
                
                for($h=0;$h<count($header);$h++)
                {
                    $header[$h]["FieldName"]=str_replace("&","",(str_replace(")","",(str_replace("(","",(str_replace("]","",(str_replace("[","",str_replace(".","",$header[$h]["FieldName"]))))))))));
                }
                
                for($i=0;$i<count($result);$i++)
                {
                    $Sorsz=$i+$start+1;
                    $vissza["data"][]=array("DT_RowId"=>"row_".($i+$start+1),
                        "Sorsz"=>(string)($Sorsz),"Revision"=>$result[$i]["Revision"]);
                    
                    for($j=0;$j<count($header);$j++)
                    {
                        if(isset($result[$i]["Cells"][$j]["Comments"])) //the cell content comment
                        {
                            $vissza["data"][count($vissza["data"])-1]=array_merge($vissza["data"][count($vissza["data"])-1],array($header[$j]["FieldName"]=>$result[$i]["Cells"][$j]["Value"]."¤1"));
                        }
                        else
                        {
                            $vissza["data"][count($vissza["data"])-1]=array_merge($vissza["data"][count($vissza["data"])-1],array($header[$j]["FieldName"]=>$result[$i]["Cells"][$j]["Value"]."¤0"));
                        }    
                    }   
                    $c++;
                }
    
                $vissza["options"]=array();
                $vissza["files"]=array();
                $vissza["laststart"]=$start;
                $vissza["lastlength"]=$hossz;
                $vissza["recordsTotal"]=$selRes[0]["darab"];
                $vissza["recordsFiltered"]=$selRes[0]["darab"];
                $vissza["draw"]= mysqli_real_escape_string($db->getHandler(),$_REQUEST["draw"]);
                $v=json_encode($vissza);
                
                return $v;
            }
            else
            {
                if(isset($_REQUEST["action"]))
                {
    .
    .
    .
    

    and the ajax parameter

    table.ajax.url('index.php?module=TablePage&method=LoadData&ID='+result.tableId+"&tableName="+result.tableName);
    
  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin

    It looks like the Ajax call to index.php is stalling. Is there anything shown in the server's error logs perhaps?

    Allan

  • urbanjurbanj Posts: 20Questions: 4Answers: 0

    I not see error! The index.php starting call LoadData modul, and LoadData return ne data package.
    Where did you see the wrong run?

This discussion has been closed.