Base solution for your next web application
Open Closed

Call Controller Method instead of service method for jtable #3387


User avatar
0
microbridge created

Hi, i am using ASP.NET MVC 5.X with JQuery. I want to call a controller method instead of service method when loading data into a jtable. I need to store some data in viewdata or as a session object and populate the jtable from one of those objects instead of pulling data from a database. Whats is the best way to achieve this using abp.


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You just need to set your controller action's url to jTable's list action

    actions: {
        listAction: '/Demo/StudentList'
    }
    

    For more info, you can check jTable samples and docs. <a class="postlink" href="http://www.jtable.org/">http://www.jtable.org/</a>

    Thanks.

  • User Avatar
    0
    microbridge created

    I tried doing s before posting but i get a javascript error - Uncaught TypeError: originalListAction.method is not a function.

    see code below

    Javascript Script Code:

    _$bagsTable.jtable({

            title: app.localize('Bags'),
    
            actions: {
                listAction:  "/Mpa/DepositProcessingToTreasury/GetBagsToBeTransfered"
            },
    
            fields:
            {
                id: {
                    key: true,
                    list: false
                },
    
                bagNo: {
                    title: app.localize('BagNo'),
                    width: '10%'
                },
                fit: {
                    title: app.localize('Fit'),
                    width: '10%'
                },
    
                currencyCode: {
                    title: app.localize('Currency'),
                    width: '25%'
                },
                bagTotal: {
                    title: app.localize('Total'),
                    width: '10%'
                }
            }  
    
        });
    

    Controller :

    public JsonResult GetBagsToBeTransfered() {

            try
            {
                List&lt;CashMovementTransactionBagListDto&gt; result = new List&lt;CashMovementTransactionBagListDto&gt;();
    
                if (ViewData["Bags"] != null)
                {
                    var bagList = ViewData["Bags"] as List&lt;CreateOrUpdateCashMovementBagDto&gt;;
    
    
                    foreach (var bag in bagList)
                        result.Add(new CashMovementTransactionBagListDto { BagNo = bag.Bag.BagNo, BagTotal = 0, CashMovementTransactionId = 0, CurrencyCode = "JMD", CurrencyId = 1, Fit = true, Id = 0 });
    
    
    
                }
                return Json(new { Result = "OK", Records = result });
    
    
            }
            catch (Exception ex)
            {
                return Json(new { Result = "ERROR", Message = ex.Message });
            }
    
    
        }
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Then, there might be a bug in jTable. Let us check this and get back to you.

    Thanks.