cancel
Showing results for 
Search instead for 
Did you mean: 

How to fill a table from an ajax result

Former Member
0 Kudos

Hello,

I am trying to fill a table given the data that I get from an ajax function here is the code and the solution I am trying to apply.

SLOUTION:

I'm trying to set the results to a property in a model that I have defined in manifest (It works the property sets properly) but once I got this I don't know how to get a specified field on the results.

example: "modelDefault>/DetalleStockDuplicadosSet" It has an array with the results. How to acccess to a field "Descripcion" of the array and display on the table?

XML TABLE:

<Table id="tableLlaves" growingScrollToLoad="true" growing="true" items="{path: 'modelDefault>/DetalleStockDuplicadosSet'}">
				     <columns>
				     	<Column width="100px" minScreenWidth="Tablet" demandPopin="true" visible="false"> 
							<header>
								<Label text="Id"/>
							</header>
						</Column>
				      	<Column width="100px" minScreenWidth="Tablet" demandPopin="true"> 
							<header>
								<Label text="Tipo Llave"/>
							</header>
						</Column>
						<Column width="100px" minScreenWidth="Tablet" demandPopin="true"> 
							<header>
								<Label text="Confirmar"/>
							</header>
						</Column>
						<Column width="100px" minScreenWidth="Tablet" demandPopin="true"> 
							<header>
								<Label text="Incidencia"/>
							</header>
						</Column>
						<Column width="100px" minScreenWidth="Tablet" demandPopin="true"> 
							<header>
								<Label text="Texto de incidencia"/>
							</header>
						</Column>
				     </columns>
				     <items>
                       <ColumnListItem>
                         <cells>
                         	<ObjectIdentifier title="{Id}"/>
                         	<Text text="{path:'Descripcion'}"/>
                         	<CheckBox id="checkID" checked="false"/>
                         	<Select id="sel"/>
                         	<Input id="__input0" ariaLabelledBy="__label8" width="100%"/>
                         </cells>
                       </ColumnListItem>
                    </items>
            	</Table>

SCRIPT:

var selectedId = that.getOwnerComponent().getModel("modelDefault").getProperty("/Id");
var that = this;
$.ajax({
    type: 'GET',
url : "/sap/opu/odata/SAP/ZFIO_LLAVES_STOCK_DPC_SRV/DetalleStockDuplicadosSet?$filter=IId eq '"+selectedId+"'&$format=json",
    dataType: 'json',
    success: function(data,textStatus,jqXHR) {
        var resultados = data.d.results;
        that.getView().getModel("modelDefault").setProperty("/DetalleStockDuplicadosSet", resultados);// resultados[0], false
        that.getView().getModel("modelDefault").setProperty("/EstadosSet", data.d.results);
	console.log(that.getView().getModel("modelDefault").getProperty("/DetalleStockDuplicadosSet"));
    },
    error : function(jqXHR,textStatus,errorThrown) {
	console.log(errorThrown);
	BaseController.getRouter().navTo("ObjectNotFound");
    }
});

Accepted Solutions (0)

Answers (1)

Answers (1)

vaibhav_gb
Explorer

Hi,

Try binding in this format "{modelName>Key}, in your case something like this

<Text text="{modelDefault>Descripcion}"/>

Also remove the id from Checkbox, Select and Input.

regards

GB