Click here to Skip to main content
15,891,033 members
Home / Discussions / Web Development
   

Web Development

 
GeneralRe: Refresh WebGrid Pin
Kevin Marois3-May-17 12:31
professionalKevin Marois3-May-17 12:31 
GeneralRe: Refresh WebGrid Pin
Richard Deeming4-May-17 0:47
mveRichard Deeming4-May-17 0:47 
GeneralRe: Refresh WebGrid Pin
Kevin Marois4-May-17 7:11
professionalKevin Marois4-May-17 7:11 
GeneralRe: Refresh WebGrid Pin
Richard Deeming4-May-17 7:32
mveRichard Deeming4-May-17 7:32 
GeneralRe: Refresh WebGrid Pin
Kevin Marois4-May-17 7:37
professionalKevin Marois4-May-17 7:37 
Questionnew page template not adding new css Pin
Member 131671632-May-17 9:47
Member 131671632-May-17 9:47 
AnswerRe: new page template not adding new css Pin
Heather Maga3-May-17 10:07
professionalHeather Maga3-May-17 10:07 
QuestionJavaScript WebGrid Clone Row Problem Pin
Kevin Marois1-May-17 12:20
professionalKevin Marois1-May-17 12:20 
[UPDATE]
I solved this. I set the WebGrid's Id by doing
htmlAttributes: new { id = "MyGrid" }
then doing this in the JS
var table = document.getElementById('MyGrid');
[UPDATE]

I'm trying to insert a new row into a WebGrid. I'm getting an error "Uncaught TypeError: Cannot read property '1' of undefined"

My WebGrid code
@using (@Html.BeginForm("Index", "Home"))
{

        @{
            var grid = new WebGrid(Model, rowsPerPage: 10, ajaxUpdateContainerId: "divData", canPage: true);

            @grid.GetHtml(
            tableStyle: "webgrid-table",
            headerStyle: "webgrid-header",
            footerStyle: "webgrid-footer",
            alternatingRowStyle: "webgrid-alternating-row",
            selectedRowStyle: "webgrid-selected-row",
            rowStyle: "webgrid-row-style",
            mode: WebGridPagerModes.All,
            columns:
            grid.Columns
            (
                grid.Column(columnName: "RowId", header: "Row Id", format: @@item.RowId),
                grid.Column(columnName: "SiteId", header: "Site Id", format: @@item.SiteId),

                // other columns omitted
            ))
        }

}
and my JavaScript
function createNewRow(model)
{
    // Make a copy of the first row
    var table = document.getElementById('divData');
    var new_row = table.rows[1].cloneNode(true);        // <======  Error occurs here. The Table exists, the rows collection does not.
    var len = table.rows.length;
    new_row.cells[0].innerHTML = len;

    // Copy the model's data to the new row
    new_row.cells[1].value = model.SiteId;
    new_row.cells[2].value = model.InstrumentId;
    new_row.cells[3].value = model.TowerLocation;
    new_row.cells[4].value = model.BayLocation;
    new_row.cells[5].value = model.BaySerialNo;
    new_row.cells[6].value = model.BayStatus;
    new_row.cells[7].value = model.AccessionId;
    new_row.cells[8].value = model.Result;
    new_row.cells[9].value = model.AssayName;
    new_row.cells[10].value = model.Started;
    new_row.cells[11].value = model.Completed;
    new_row.cells[12].value = model.TestSummary;

    // Add the new row to the table
    table.appendChild(new_row);
}

There are rows in the table, so why doesn't the Rows collection exist? I can see row data in the Console.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.


modified 2-May-17 13:16pm.

Questionhtml incorrectly displayed dashed border Pin
dcof26-Apr-17 9:09
dcof26-Apr-17 9:09 
AnswerRe: html incorrectly displayed dashed border Pin
User 418025428-Apr-17 9:32
User 418025428-Apr-17 9:32 
Questionsave client side form data to disk Pin
bandula ck26-Apr-17 2:55
bandula ck26-Apr-17 2:55 
AnswerRe: save client side form data to disk Pin
W Balboos, GHB26-Apr-17 6:28
W Balboos, GHB26-Apr-17 6:28 
GeneralRe: save client side form data to disk Pin
bandula ck26-Apr-17 9:15
bandula ck26-Apr-17 9:15 
GeneralRe: save client side form data to disk Pin
W Balboos, GHB27-Apr-17 0:02
W Balboos, GHB27-Apr-17 0:02 
QuestionFiltering Gallery Pin
Member 1315220725-Apr-17 12:40
Member 1315220725-Apr-17 12:40 
QuestionJavaScript Question #3 Pin
Kevin Marois25-Apr-17 8:44
professionalKevin Marois25-Apr-17 8:44 
AnswerRe: JavaScript Question #3 Pin
Richard Deeming25-Apr-17 8:52
mveRichard Deeming25-Apr-17 8:52 
GeneralRe: JavaScript Question #3 Pin
Kevin Marois25-Apr-17 10:51
professionalKevin Marois25-Apr-17 10:51 
GeneralRe: JavaScript Question #3 Pin
Kevin Marois25-Apr-17 12:29
professionalKevin Marois25-Apr-17 12:29 
AnswerRe: JavaScript Question #3 Pin
Jon McKee25-Apr-17 9:53
professionalJon McKee25-Apr-17 9:53 
GeneralRe: JavaScript Question #3 Pin
Kevin Marois25-Apr-17 10:51
professionalKevin Marois25-Apr-17 10:51 
GeneralRe: JavaScript Question #3 Pin
Kevin Marois25-Apr-17 10:54
professionalKevin Marois25-Apr-17 10:54 
GeneralRe: JavaScript Question #3 Pin
Richard Deeming25-Apr-17 12:31
mveRichard Deeming25-Apr-17 12:31 
GeneralRe: JavaScript Question #3 Pin
Kevin Marois25-Apr-17 12:32
professionalKevin Marois25-Apr-17 12:32 
QuestionNext JavaScript Question Pin
Kevin Marois25-Apr-17 7:50
professionalKevin Marois25-Apr-17 7:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.