locked
Repeated value should come only once RRS feed

  • Question

  • User1052662409 posted

    Hi All,

    I am binding  a table using jquery ajax method.

    code

    function BindAssets() {
    
                    $.ajax({
                        url: "/Assets.asmx/GetListOfAssets",
                        dataType: "json",
                        method: "POST",
                        contentType: 'application/json; charset=utf-8',
                        success: function (data, success) {
    
                            var result = $.parseJSON(data.d);
                            var AssetTable = $('#tblAssets tbody');
                            AssetTable.empty();
    
                            var assetdiv = "";
                            for (var i in result) {
    
                                assetdiv = '<tr class="data-assets">' +  
                                     '<td >' + result[i].type +'</td><td >' + [Number(i) + 1] +'</td><td ><b>' + result[i].asset_name + '</b></td>' +  
                                    '<td><input type="hidden" name="asset_name"  value="' + result[i].asset_name + '" class="cname"><input type="hidden" name="asset_id"  value="' + result[i].asset_id + '" class="cid"><input type="text" class="form-control date-inputmask cquantity" name="txtQuantity' + i +'"  placeholder="Quantity" onkeypress="return isNumber(event)"/></td>' +  
                    '<td><input type="date" class="form-control date-inputmask cdate" name="txtIssueDate'+i+'"  placeholder="dd/mm/yyyy" /></td>' +  
                    '<td><input type="text" class="form-control date-inputmask ccondition" name="txtPhysicalCondition'+i+'"  placeholder="Physical Condition" /></td>' +  
                    '<td> <input type="text" class="form-control cremarks" placeholder="Comment / Remarks"  name="txtRemarks'+i+'"  /></td>' +
                                    '</tr>';  
                             
                                $('#tblAssets').append(assetdiv);
    
                            }
    
    
                        },
                        error: function (err) {
    
                            console.log(err);
                        }
                    });
            }

    The output of the table as below.

    Capture

    I want that the first cell value like "SAFETY EQUIPMENTS" should come once as a heading upon the items same goes with "OFFICE SETUP".

    How to I put as heading every group.

    Please suggest.

    Monday, August 31, 2020 6:53 PM

Answers

  • User-474980206 posted

    simple control break logic:

                            var lastType = null;
                            for (var i in result) {
                                var type = result[i].type;
                                if (type == lastType) 
                                       type = "&nbsp;";
                                else
                                       lastType = type;
                                assetdiv = '<tr class="data-assets">' +  
                                     '<td >' + type +'</td><td >' + [Number(i) + 1] +'</td><td ><b>' + result[i].asset_name + '</b></td>' +  
                                    '<td><input type="hidden" name="asset_name"  value="' + result[i].asset_name + '" class="cname"><input type="hidden" name="asset_id"  value="' + result[i].asset_id + '" class="cid"><input type="text" class="form-control date-inputmask cquantity" name="txtQuantity' + i +'"  placeholder="Quantity" onkeypress="return isNumber(event)"/></td>' +  
                    '<td><input type="date" class="form-control date-inputmask cdate" name="txtIssueDate'+i+'"  placeholder="dd/mm/yyyy" /></td>' +  
                    '<td><input type="text" class="form-control date-inputmask ccondition" name="txtPhysicalCondition'+i+'"  placeholder="Physical Condition" /></td>' +  
                    '<td> <input type="text" class="form-control cremarks" placeholder="Comment / Remarks"  name="txtRemarks'+i+'"  /></td>' +
                                    '</tr>';  
                             
                                $('#tblAssets').append(assetdiv);
    
                            }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 31, 2020 7:48 PM