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

Web Development

 
QuestionRefresh WebGrid Pin
Kevin Marois2-May-17 11:39
professionalKevin Marois2-May-17 11:39 
SuggestionRe: Refresh WebGrid Pin
Richard Deeming3-May-17 10:52
mveRichard Deeming3-May-17 10:52 
GeneralRe: Refresh WebGrid Pin
Kevin Marois3-May-17 10:54
professionalKevin Marois3-May-17 10:54 
GeneralRe: Refresh WebGrid Pin
Richard Deeming3-May-17 11:03
mveRichard Deeming3-May-17 11:03 
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 
Kevin Marois wrote:
.find("span[x-RowId='" + model.RowId + "']")
...
$row.find("span[x-RowId]").data("rowId", model.RowId)

That's a bit confusing - you're looking for an attribute called x-RowId, but you're updating the data-row-id attribute. It would probably be better to stick with the data-row-id attribute, since that's the standard way of associating extra data with an element.

There's also no need to update the row ID for an existing row.
JavaScript
proxy.on('notifyAllClientsOfChanges', function (model) {
    
    console.log("notifyAllClientsOfChanges called");
    
    var $row = $(".webgrid-table").find("span[data-row-id='" + model.RowId + "']").closest("tr");
    console.log(model.RowId, $row);
    
    if (!$row.length) {
    
        var table = document.getElementById('MyGrid');
        console.log("TABLE", table);
        
        var len = table.rows.length;
        console.log("len = ", len);
        
        var new_row = table.rows[1].cloneNode(true);
        console.log("new_row", new_row);
        
        new_row = table.tBodies[0].appendChild(new_row);
        console.log("new_row", new_row);
        
        $row = $(new_row);
        $row.find("span[data-row-id]").data("rowId", model.RowId).text(model.RowId);
    }
    
    console.log("SETTING ROW VALUES");
    
    $row.find(".x-SiteId").text(model.SiteId);
    $row.find(".x-InstrumentId").text(model.InstrumentId);
    $row.find(".x-TowerLocation").text(model.TowerLocation);
    $row.find(".x-BayLocation").text(model.BayLocation);
    $row.find(".x-BaySerialNo").text(model.BaySerialNo);
    $row.find(".x-BayStatus").text(model.BayStatus);
    $row.find(".x-AccessionId").text(model.AccessionId);
    $row.find(".x-Result").text(model.Result);
    $row.find(".x-AssayName").text(model.AssayName);
    $row.find(".x-Started").text(model.Started);
    $row.find(".x-Completed").text(model.Completed);
    $row.find(".x-TestSummary").text(model.TestSummary);
    
    console.log("DONE");
}

It looks like the server is sending 0 as the RowId, so you'd need to fix that on the server.

The appendChild method will always insert the element at the end of the specified parent. If you want to insert it at a specific position, you'll need to find the row that should immediately follow it, and use insertBefore[^] to add the node. Something like this:
JavaScript
var new_row = table.rows[1].cloneNode(true);
console.log("new_row", new_row);

var before_row = null;
var before_value = null;

$(".webgrid-table tr").each(function(){
    var value = $(this).find(".x-Started").text();
    
    // TODO: Convert the value to an appropriate type for sorting if necessary:
    if (value < model.Started) {
        if (!before_row || before_value < value) {
            before_row = this;
            before_value = value;
        }
    }
});

if (before_row) {
    new_row = table.tBodies[0].insertBefore(new_row, before_row);
}
else {
    new_row = table.tBodies[0].appendChild(new_row);
}

console.log("new_row", new_row);

If you can't convert the text value of the x-Started span to an appropriate type for sorting, you'll need to use another data- attribute to store and retrieve a sortable value.



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


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 
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 

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.