Angularjs Help ekak

sp3co

Well-known member
  • Sep 22, 2016
    1,495
    425
    83
    Katubedda
    මචන්ලා, මගේ project එකක පොඩි වැඩකට උදව්වක් ඕනේ. Angular project එකක්..

    මේකයි සින් එක.

    මට ඕනේ dynamically table එකක් create කරන්න.

    No of columns = 3
    How many = 10.
    අපි හිතමු user input කරන්නේ ඔය දෙක කියල. ඒ කියන්නේ columns 3e table එකක් create වෙන්න ඕනේ සහ එක ෆිල් වෙන්න ඕනේ මෙහෙම(a අකුරෙන් 10 පාරක්). (letter 'a' hard-code කරලා තියෙන්නේ)

    a | a | a
    a | a | a
    a | a | a
    a

    මේක කොහොමද angular වලින් කරන්නේ. nested ng-repeat වලින් කරන්න තේරෙන්නේ නෙ. Stackoverflow ඇහුවට උන්ට ප්‍රශ්නේ තේරෙන්නේ නැතුව රෙප් කපනවා.

    angular දන්නා එකෙක් පුලුවන්නම් උදව්වක් දියන්, ලොකු දෙයක් බන්. දන්නේ නැත්තන් bump එකක්වත් දාගෙන පලයන්. Thanks මචන්ලා
     

    sp3co

    Well-known member
  • Sep 22, 2016
    1,495
    425
    83
    Katubedda
    var myapp = angular.module("mymod",[]);
    myapp.controller("mycon", function ($scope){


    Your code

    });

    Oya machan angular app eke code eka ne..man angular app eke tikak gahala tiyenne..mata one mama kiuwa widiyata table ekak dynamically create karana code eka witharai..anith ewa shape..

    Anyway Thanks machan
     

    Extra One

    Well-known member
  • Jan 12, 2012
    3,430
    1,139
    113
    json array object ekak hadagenna. eke eka object ekak name value pair thunak wenna. eka ng repeat walin retrieve karanna
     

    izuru_reloaded

    Active member
  • Dec 1, 2008
    590
    120
    43
    GAMPAHA
    try this machan

    angular
    $scope.repeatCount = 10;

    $scope.columnCount = 3;
    $scope.rowCount = Math.ceil($scope.repeatCount / $scope.columnCount)

    $scope.range = function (n) {
    return new Array(n);
    };

    $scope.checkRepeatCount = function (parentIndex, index) {

    if (parentIndex == $scope.rowCount-1 && ((parentIndex * $scope.columnCount) + index >= $scope.repeatCount)) return false;
    return true;
    }

    ------------------------------------------------------------------------------------------------------------------

    html

    <table class="table table-bordered">
    <tr ng-repeat="a in range(rowCount) track by $index" ng-init="sectionIndex = $index">
    <td ng-repeat="a in range(columnCount) track by $index" ng-if="checkRepeatCount(sectionIndex,$index)">a</td>

    </tr>

    </table>
     
    • Like
    Reactions: sp3co

    sp3co

    Well-known member
  • Sep 22, 2016
    1,495
    425
    83
    Katubedda
    json array object ekak hadagenna. eke eka object ekak name value pair thunak wenna. eka ng repeat walin retrieve karanna

    try this machan

    angular
    $scope.repeatCount = 10;

    $scope.columnCount = 3;
    $scope.rowCount = Math.ceil($scope.repeatCount / $scope.columnCount)

    $scope.range = function (n) {
    return new Array(n);
    };

    $scope.checkRepeatCount = function (parentIndex, index) {

    if (parentIndex == $scope.rowCount-1 && ((parentIndex * $scope.columnCount) + index >= $scope.repeatCount)) return false;
    return true;
    }

    ------------------------------------------------------------------------------------------------------------------

    html

    <table class="table table-bordered">
    <tr ng-repeat="a in range(rowCount) track by $index" ng-init="sectionIndex = $index">
    <td ng-repeat="a in range(columnCount) track by $index" ng-if="checkRepeatCount(sectionIndex,$index)">a</td>

    </tr>

    </table>


    Thanks machanla.. wade karagatta...