Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9121819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:56:53+00:00 2026-06-17T05:56:53+00:00

I have got a task to do knockout.js in ruby on rails. I want

  • 0

I have got a task to do knockout.js in ruby on rails. I want to list my database values in a table format.
My Index page is

<%= javascript_include_tag "knockout-2.2.0", "knockout.simpleGrid.1.3" %>

<style type='text/css'> 
    .ko-grid { margin-bottom: 1em; width: 25em; border: 1px solid silver; background-color:White; }
    .ko-grid th { text-align:left; background-color: Black; color:White; }
    .ko-grid td, th { padding: 0.4em; }
    .ko-grid tr:nth-child(odd) { background-color: #DDD; }
    .ko-grid-pageLinks { margin-bottom: 1em; }
    .ko-grid-pageLinks a { padding: 0.5em; }
    .ko-grid-pageLinks a.selected { background-color: Black; color: White; }
    .liveExample { height:20em; overflow:auto } /* Mobile Safari reflows pages slowly, so fix the height to avoid the need for reflows */
</style>
<% @users.each do |user| %>
<script type="text/javascript">
 $(document).ready(function() {

    var initialData = [
     {name:<%= @user_names.to_json.html_safe%>, place: <%= @user_places.to_json.html_safe%> }
    ];

var PagedGridModel = function(items) {
    this.items = ko.observableArray(items);

    this.addItem = function() {
        this.items.push({ name: "New item", place: "dfgd"});
    };

    this.sortByName = function() {
        this.items.sort(function(a, b) {
            return a.name < b.name ? -1 : 1;
        });
    };

    this.jumpToFirstPage = function() {
        this.gridViewModel.currentPageIndex(0);
    };

    this.gridViewModel = new ko.simpleGrid.viewModel({
        data: this.items,
        columns: [
            { headerText: "Name", rowText: "name" },
            { headerText: "Place", rowText: "place" }

        ],
        pageSize: 4
    });
};

ko.applyBindings(new PagedGridModel(initialData));
    });
 </script>
 <%end%>
<div data-bind='simpleGrid: gridViewModel'> <br/></div>

<button data-bind='click: addItem'>
    Add item
</button>

<button data-bind='click: sortByName'>
    Sort by name
</button>

<button data-bind='click: jumpToFirstPage, enable: gridViewModel.currentPageIndex'>
    Jump to first page
</button> 

The result while running is

Name                          Place
Nithin,Vipin,Jetson     Vatakara,Calicut,Aluva

All names are came in single row and same as in the case of place.
How can i solve it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:56:56+00:00Added an answer on June 17, 2026 at 5:56 am

    In place of this

     var initialData = [
         {name:<%= @user_names.to_json.html_safe%>, place: <%= @user_places.to_json.html_safe%> }
        ];
    

    try giving user_name one by one via iteration.

    I’m not sure. will you please try this.

     $(document).ready(function() {
    var initialData = new Array;
    <% @users.each do |user| %>
    initialData.push({name: "<%= user.name %>" , place: "<%= user.place %>" }) ;
    <% end %>   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got a task table in my database with a priority field containing
I have got a huge list of tasks loaded on the start. I want
I have got a list of many web page URLs.. and all of them
I have got a task to do knockout.js. Here i have a model employee
I am new in Java and have got as a task to find out,
Have got an NSString *str = @12345.6789 and want to find out if there
i have got <div><a class='link' href='index.php' data-container='target'>Load</a></div> <div class='target'></div> i need to write jquery
I have got a table [newsletter] in the db, which saves the email address,
I have got a task where in I have to Draw 2 lines on
Hello guru of programming! Today I have got the task from my manager to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.