仅当返回到另一页并重新访问该URL时才显示结果

时间:2016-11-24 11:51:14

标签: javascript php html

当用户打开页面[orders.php]

时,我们会显示所有结果

enter image description here

我们根据所选的From& amp;显示结果。到目前为止,

enter image description here

点击"重置"按钮选择日期正在重置。但结果没有显示

enter image description here

值仅在我们返回到另一个页面并再次打开相同的URL时显示。 [假设转到products.php&重新访问orders.php]

HTML

<form name="frmSearch" method="post" action="">
    <input type="text"  id="post_at" value="<?php if($orderFromDate!=''){ echo $orderFromDate; }?>" name="post_at"  />       
    <input type="text"  id="post_at_to_date" value="<?php if($orderToDate!=''){ echo $orderToDate; }?>" name="post_at_to_date"  />
    <input type="submit" name="search" value="search"  />     
    <input type="button" value="Reset"  id="clear-dates" >
</form>

脚本

jQuery.datepicker.setDefaults({
showOn: "button",
buttonImage: "datepicker.png",
buttonText: "Date Picker",
buttonImageOnly: true,
dateFormat: 'yy-mm-dd'  
});
$(function() {
$("#post_at").datepicker();
$("#post_at_to_date").datepicker();
});

var __TEST_DATA__=eval('<?php echo getDesignerCollection();?>');
var grid_demo_id = "myGrid" ;
var dsOption= {
    fields :[   
        {name : 'entity_id'  }, 
        {name : 'entity_id'  },
        {name : 'created_at'},                  
    ],
    recordType : 'array',
    data : __TEST_DATA__
}   

function my_renderId(value ,record,columnObj,grid,colNo,rowNo)
    {
        var no= record[columnObj.fieldIndex];

        return "<input type='checkbox' value='"+record[0]+"' name='userID'/>";
    }

    var colsOption = [  
        {id: 'entity_id' , header: "Order Id" , width :"15",renderer : my_renderId},
        {id: 'entity_id' , header: "Order Id" , width :"75"},

        {id: 'created_at' , header: "Order Date" , width :"120"}

    ];

    var gridOption={
        id : grid_demo_id,  
        //height: "285",  //"100%", // 330, 
        pageSize:20,    
        pageSizeList : [5,10,15,20],
        container : 'myGrid', 
        replaceContainer : true,    
        dataset : dsOption ,
        columns : colsOption ,
        toolbarContent : 'nav goto | pagesize | filter state | sortable | search',
        onRowClick:function(value, record , cell, row,  colNO, rowNO,columnObj,grid){
        }
    };
    var mygrid=new Sigma.Grid(gridOption);
    Sigma.Util.onLoad( Sigma.Grid.render(mygrid) );

    function doFilter() {
        var filterInfo=[
            {
                fieldName : $('select[id=f_value2]').val(),
                logic : "startWith",
                value : Sigma.Util.getValue("f_value1")
            },
            {
                fieldName : Sigma.Util.getValue("f_fieldName12"),
                logic : "greatEqual",
                value : Sigma.Util.getValue("f_value12")
            }
        ]
        var grid=Sigma.$grid("myGrid");
        var rowNOs=grid.applyFilter(filterInfo); 
    }
    function doUnfilter(){
        var grid=Sigma.$grid("myGrid1");
        var rowNOs=grid.unfilterGrid();

    }   

PHP

function getDesignerCollection()
{
    $user_home = new USER();
    require_once '../../app/Mage.php';
    Mage::app(); 
    $stmts = $user_home->runQuery("SELECT * FROM tbl_users WHERE userID=:uid");
    $stmts->execute(array(":uid"=>$_SESSION['userSession']));
    $rows = $stmts->fetch(PDO::FETCH_ASSOC);
    if(isset($_POST['post_at']) && $_POST['post_at']!='')
    {
        $orderFromDate=$_POST['post_at']." 00:0:00";
    }
    else
    {
        $orderFromDate='';
    }
    if(isset($_POST['post_at_to_date']) && $_POST['post_at_to_date']!='')
    {
        $orderToDate=$_POST['post_at_to_date']." 59:59:59";
    }
    else{$orderToDate='';}
    $accountType=$rows['type'];
    if($accountType=="admin"){

        $order = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('designer_id',array('nin'=>'0'));
        if($orderFromDate!='')$order->addFieldToFilter('created_at',array('gteq'=>$orderFromDate));
        if($orderToDate!='')$order->addFieldToFilter('created_at',array('lteq'=>$orderToDate));
    }
    else
    {
        $order = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('designer_id',array('like' => '%'.$_SESSION['userSession'].'%'));
    }

    $i=0;
    foreach ($order as $orderData)  
    {

        $orderitems=$orderData['dproduct_id'];
        $orderitemsarray=explode(",",$orderitems);
        $k=0;

        $oDate = new DateTime($orderData['created_at']);
        $sDate = $oDate->format("Y-m-d");
        while($k < count($orderitemsarray))
        {
           if($orderitemsarray[$k]!='0')
          {

            $stmtorders = $user_home->runQuery("SELECT * FROM order_details WHERE designerorder_id=:designerorder_id");
            $stmtorders->execute(array(":designerorder_id"=>$orderData['entity_id']));
            $roworders = $stmtorders->fetch(PDO::FETCH_ASSOC);

            if($roworders['designerorder_id']==''){$dorderStatus="Unpaid";}else{$dorderStatus=$roworders['paid_status'];}

          $productdetail=Mage::getModel('catalog/product')->load($orderitemsarray[$k]); 
          $designerName=getDesignerName($productdetail->getDesignerID())." -(".$productdetail->getDesignerID().")";   
          $responce[]=array($orderData->getIncrementId(),$orderData->getIncrementId(),$orderitemsarray[$k],$productdetail->getName(),$designerName,$orderData['status'],$orderData['grand_total'],$orderData['customer_email'],$orderData['shipping_description'],$dorderStatus,$sDate);

         }
        $k++; $i++;
        }

    }       echo json_encode($responce);    

}   

1 个答案:

答案 0 :(得分:0)

你可以在代码片段中使用这个小代码:)我添加了一些代码来检测页面重新加载。

$("#clear-dates").click(function(){
 location.reload();
});

&#13;
&#13;
$("#clear-dates").click(function() {
  location.reload();
});
//You can ignor this part
$(window).bind('beforeunload',function(){
    return 'do you really want to leave?';
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="button" value="Reset" id="clear-dates">
&#13;
&#13;
&#13;