phuongbao90
5/14/2018 - 7:47 AM

Javascript snippet

Javascript snippet

<link rel="stylesheet" href="https://unpkg.com/ag-grid/dist/styles/ag-grid.css">
<link rel="stylesheet" href="https://unpkg.com/ag-grid/dist/styles/ag-theme-balham.css">

<div id=""></div>



<script src="https://unpkg.com/ag-grid/dist/ag-grid.min.noStyle.js"></script>
<script type="text/javascript" charset="utf-8" >

  document.addEventListener("DOMContentLoaded",function(){
            var columnDefs = [
        //   {headerName: "#", field: "#"},
        {headerName: "name", field: "name"},
        {headerName: "image", field: "image",
            valueGetter: function aPlusBValueGetter(params) {
                // return params.data;
                return `<img src="{{asset("storage/images/shoes/male/adidas/1 (21).png")}}" >`;
            }},
        {headerName: "description", field: "description"},
        {headerName: "price", field: "price",valueFormatter: currencyFormatter, cellClass: 'number-cell'},
        {headerName: "gender", field: "gender"},
        //   {headerName: "category", field: "category"},
        //   {headerName: "size", field: "size"},
        //   {headerName: "color", field: "color"},
        //   {headerName: "available", field: "price"},
        //   {headerName: "delete", field: "price"},
        ];

        var gridOptions = {
            columnDefs: columnDefs,
            enableSorting: true,
            enableFilter: true,
            enableColResize: true,
            onGridReady: function(params) {
                params.api.sizeColumnsToFit();
            }
        };

        var eGridDiv = document.querySelector('#myGrid');

        new agGrid.Grid(eGridDiv, gridOptions);

        axios.get('http://shoes-store.mc/admin/getTable').then((res) => {
            gridOptions.api.setRowData(res.data);
        })
    })

    function currencyFormatter(params) {
        return  formatNumber(params.value) + ' VND';
    }

    function formatNumber(number) {
        // this puts commas into the number eg 1000 goes to 1,000,
        // i pulled this from stack overflow, i have no idea how it works
        return Math.floor(number).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
    }


</script>
//Fisher-Yates (aka Knuth) Way

function shuffle(array) {
  var currentIndex = array.length, temporaryValue, randomIndex ;

  // While there remain elements to shuffle...
  while (0 !== currentIndex) {

    // Pick a remaining element...
    randomIndex = Math.floor(Math.random() * currentIndex);
    currentIndex -= 1;

    // And swap it with the current element.
    temporaryValue = array[currentIndex];
    array[currentIndex] = array[randomIndex];
    array[randomIndex] = temporaryValue;
  }

  return array;
}
var div = document.querySelectorAll('div'),
			result;
		for (var i = 0; i < div.length; i++) {
	    result = div[i];
	    result.addEventListener('click', function() {
			alert(this.innerHTML);
		});
	}
!function(t){"use strict";function e(t,e){return function(o){o.target&&o.target.matches(t)&&e.apply(this,arguments)}}Element.prototype.matches||(Element.prototype.matches=Element.prototype.matchesSelector||Element.prototype.mozMatchesSelector||Element.prototype.msMatchesSelector||Element.prototype.oMatchesSelector||Element.prototype.webkitMatchesSelector||function(t){for(var e=(this.document||this.ownerDocument).querySelectorAll(t),o=e.length;--o>=0&&e.item(o)!==this;);return o>-1}),t.addDynamicEventListener=function(t,o,n,r,c){t.addEventListener(o,e(n,r),c)}}(this);