2016-04-05 67 views
0

Fiyat ve Değer sütun adım var. Ve jqgrid altbilgi değerini kullanıyorum.jqgrid'teki footerdata kullanarak satırları ve toplamı çarpma

Örnek bu 2 sütun I altbilgi verileri kullanılarak Fiyat ve Değer satır toplamını nasıl alabilirim Fiyat ve Değer

Price  
$25.00000 
$33.82000 
$1.00000 
$21.87125 
$9.49000 
...... 


Value 
$5,000.00 
$8,107.87 
$1,344.00 
$4,769.01 
$5,372.00 
... 

. Ayrıca

, birden nasıl Num1xNum2

yani

Num1 Num2 RESULT 
    4  20  80 

her row num1 x row num2 ve ekranın değeri burada benim kodudur. not: i 'toplamı' bana verir 'NaN' değeri

<!DOCTYPE html> 
<html lang="en"> 
<head> 


    <!------------------------------------------> 
     <meta http-equiv="X-UA-Compatible" content="IE=edge" /> 

    <link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.2/themes/redmond/jquery-ui.css" /> 
    <link rel="stylesheet" type="text/css" href="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-4.4.5/css/ui.jqgrid.css" /> 
    <style type="text/css"> 
     html, body { font-size: 75%; } 
    </style> 
<script type="text/ecmascript" src="https://code.jquery.com/jquery-1.12.0.min.js"></script> 
    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.2/jquery-ui.min.js"></script> 
    <script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-4.4.5/js/i18n/grid.locale-en.js"></script> 
    <script type="text/javascript"> 
     $.jgrid.no_legacy_api = true; 
     $.jgrid.useJSON = true; 
    </script> 
    <script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-4.4.5/js/jquery.jqGrid.src.js"></script> 

    <title>Jqgrid data </title> 
</head> 
<body> 
<div style="margin-left:20px"> 
    <table id="nplGrid"></table> 

</div> 
    <script type="text/javascript"> 

    $(document).ready(function() { 
     $("#nplGrid").jqGrid({ 
      url: 'json/data-bcp2.json', 
      datatype: "json", 
      colModel: [ 
       { label: 'Id', name: 'Id', width: 145 }, 
       { label: 'Symbol', name: 'Symbol', width: 90 }, 
       { label: 'Quantity', name: 'Quantity', width: 100, align: "right" }, 
       /*{ label: 'Value1', 
        name: 'Value1', 
        width: 80, 
        sorttype: 'number', 
        formatter: 'number', 
        align: 'right' 
       }, */ 
       { label: 'Price', name: 'Price', width: 180, sorttype: 'number' , align: "right",formatter: 'currency', formatoptions: { prefix: " $", suffix: " "}}, 
       { label: 'Value', name: 'Value', width: 180, sorttype: 'number', align: "right",formatter: 'currency', formatoptions: { prefix: " $", suffix: " "} }, 
       { label: 'Pledged', name: 'Pledged', width: 80, sorttype: 'integer' } , 
       { label: 'Num2', name: 'Num2', width: 80, formatter:'currency' }, 
       { label: 'Result', name: 'Result', width: 80,formatter:'currency', 
        formatter:function(cellvalue, options, rowObject) { 
         var amount = parseInt(rowObject.Num1,10), 
         tax = parseInt(rowObject.Num12,10); 
         return $.fmatter.util.NumberFormat(amount+tax,$.jgrid.formatter.currency); 
        } 
       } 
      ], 

      gridview: true, 
      rownumbers: true, 
      sortname: "invdate", 
      viewrecords: true, 
      sortorder: "desc", 
      caption: "Just simple local grid", 
      height: "100%", 
      footerrow: true, 


      loadComplete: function() { 
       var $self = $(this), 
        sum = $self.jqGrid("getCol", "Price", false, "sum"); 

       $self.jqGrid("footerData", "set", {invdate: "Total:", Price: sum}); 

        sum1 = $self.jqGrid("getCol", "Value", false, "sum"); 

       $self.jqGrid("footerData", "set", {invdate: "Total:", Value: sum1}); 
      } 


     }); 

    }); 

</script> 


</body> 
</html> 

JSON veri

{ 
    "rows":[ 
     { 
       "Id":"C14999", 
       "Symbol":"AA", 
       "Quantity":" 1,000.0000 ", 
       "Price":" $25.00000 ", 
       "Value":" $5,000.00 ", 
       "Pledged":"Y", 
       "Num1":"4", 
       "Num2":"20", 
       "RESULT":"" 
       }, 
       { 
       "Id":"C14999", 
       "Symbol":"IRTX", 
       "Quantity":" 25,343.2250 ", 
       "Price":" $82000 ", 
       "Value":" $857,107.87 ", 
       "Pledged":"Y", 
       "Num1":"12", 
       "Num2":"31", 
       "RESULT":"" 
       }, 
       { 
       "Id":"C14999", 
       "Symbol":"MMM", 
       "Quantity":" 14,344.0000 ", 
       "Price":" $1.00000 ", 
       "Value":" $4,344.00 ", 
       "Pledged":"Y", 
       "Num1":"22", 
       "Num2":"20", 
       "RESULT":"" 
       }, 
       { 
       "Id":"C14999", 
       "Symbol":"FMCX", 
       "Quantity":" 28,565.7660 ", 
       "Price":" $21.87125 ", 
       "Value":" $4,769.01 ", 
       "Pledged":"N", 
       "Num1":"232", 
       "Num2":"20" , 
       "RESULT":"" 
       }, 
       { 
       "Id":"C14999", 
       "Symbol":"CEB", 
       "Quantity":" 122,800.0000 ", 
       "Price":" $9.49000 ", 
       "Value":" $5,372.00 ", 
       "Pledged":"Y", 
       "Num1":"2", 
       "Num2":"10", 
       "RESULT":"" 
       }, 
       { 
       "Id":"C23456", 
       "Symbol":"VETF", 
       "Quantity":" 1,398,400.0000 ", 
       "Price":" $2.56000 ", 
       "Value":" $9,904.00 ", 
       "Pledged":"Y", 
       "Num1":"14", 
       "Num2":"20", 
       "RESULT":"" 
       } 
    ] 
} 

cevap

1

kullanırsanız sorun JSON veri kötü formatında. En-ABD'ye yakın bir yerde yerel olarak biçimlendirilmiş dizgeyi döndürürseniz (" $857,107.87 ", 857107.87 numarası olarak yorumlanmalıdır). Ayrıca, veriler ek sembollerle eklenir/eklenir ($, boşluklar). Bu yanlış biçimlendirilmiş verilerin toplamı hesaplanamaz ve sorttype: 'integer özelliği, loadonce: true (yerel veri sıralama) kullanırsanız, yanlış çalışır.

bir 857107.87 veya "857107.87" yerine " $857,107.87 " gibi, tipik olarak giriş kullanan ve formatters kullanılarak istemci tarafında veri * biçimlendirir. Örneğin bir sonucu olarak 857107.87 veya "857107.87" şeklinde " $857,107.87 " görüntülenecektir giriş verileri

{ label: 'Price', name: 'Price', width: 180, sorttype: 'number', align: "right", 
    formatter: 'currency', formatoptions: { prefix: " $", suffix: " "} } 

kullanabilir ancak jqGrid sütununda toplamını hesaplamak olabilir.

Son sözler. JqGrid'in eski 4.4.5 sürümünü kullanmanızı ve URL'yi http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-4.4.5/js/jquery.jqGrid.src.js URL'sinden indirmenizi tavsiye etmiyorum. Ben, npm, NuGet, bower ve Maren central (örneğin https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.13.1/js/jquery.jqgrid.min.js veya https://cdn.jsdelivr.net/free-jqgrid/4.13.1/js/jquery.jqgrid.min.js için, the wiki article bakınız) GitHub, CDN'lerin geçerli güncel sürümde 4.13.1 ücretsiz jqGrid çatal gelişir. Kaynaklardan herhangi birini seçebilirsiniz.