Hello I've been working on this for almost 2 hours now. I can't seem to find the error about the result not being shown on jqGrid. I tried echoing json_encode and it displayed. My jqGrid is working on my local site but not on the live one. I am passing a parameter so that it will not show other items that are not included.
Here's what I got:
//Controller
function all ($eid)
{
$page = isset($_POST['page'])?$_POST['page']:1;
$limit = isset($_POST['rows'])?$_POST['rows']:10;
$sidx = isset($_POST['sidx'])?$_POST['sidx']:'rank';
$sord = isset($_POST['sord'])?$_POST['sord']:'';
$start = $limit*$page - $limit;
$start = ($start<0)?0:$start;
$where = "";
$searchField = isset($_POST['searchField']) ? $_POST['searchField'] : false;
$searchOper = isset($_POST['searchOper']) ? $_POST['searchOper']: false;
$searchString = isset($_POST['searchString']) ? $_POST['searchString'] : false;
if (isset($_POST['_search']) == 'true') {
$ops = array(
'eq'=>'=',
'ne'=>'<>',
'lt'=>'<',
'le'=>'<=',
'gt'=>'>',
'ge'=>'>=',
'bw'=>'LIKE',
'bn'=>'NOT LIKE',
'in'=>'LIKE',
'ni'=>'NOT LIKE',
'ew'=>'LIKE',
'en'=>'NOT LIKE',
'cn'=>'LIKE',
'nc'=>'NOT LIKE'
);
foreach ($ops as $key=>$value){
if ($searchOper==$key) {
$ops = $value;
}
}
if($searchOper == 'eq' ) $searchString = $searchString;
if($searchOper == 'bw' || $searchOper == 'bn') $searchString .= '%';
if($searchOper == 'ew' || $searchOper == 'en' ) $searchString = '%'.$searchString;
if($searchOper == 'cn' || $searchOper == 'nc' || $searchOper == 'in' || $searchOper == 'ni') $searchString = '%'.$searchString.'%';
$where = "$searchField $ops '$searchString'";
}
if(!$sidx)
$sidx =1;
//$this->db->where('event_id', $eid);
$count = $this->db->count_all_results('table1');
if( $count > 0 ) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages)
$page=$total_pages;
$query = $this->Manager_model->getcontentfromtable($start,$limit,$sidx,$sord,$where, $eid);
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
foreach($query as $row) {
$responce->rows[$i]['rank']=$row->rank;
$pace = time_to_sec($row->runner_time)/$row->runner_cat;
$pacex = sec_to_time($pace);
$responce->rows[$i]['cell']=array($row->rank,$row->runner_name,$row->runner_cat,$row->runner_bib,$row->runner_time,$pacex);
$i++;
}
echo json_encode($responce);
}
//View
<table id="list" cellpadding="0" cellspacing="0"></table>
<div id="pager" class="scroll" style="text-align:center;"></div>
</div>
<script type="text/javascript">
$(document).ready(function (){
jQuery("#list").jqGrid({
url: '<?php echo MAINSITE_INDEX."manager/all/$eid" ?>', //another controller function for generating data
mtype : "post", //Ajax request type. It also could be GET
datatype: "json", //supported formats XML, JSON or Arrray
colNames:['Rank','Runner Name','Category','BIB','Time','Pace'], //Grid column headings
colModel :[{
name:'rank'
,index:'rank'
,width:55
},{
name:'runner_name'
,index:'runner_name'
,width:90
,editable:true
},{
name:'runner_cat'
,index:'runner_cat'
,width:80
,align:'right'
,editable:true
},{
name:'runner_bib'
,index:'runner_bib'
,width:80
,align:'rbib'
,editable:true
},{
name:'runner_time'
,index:'runner_time'
,width:80
,align:'right'
,editable:true
},{
name:'pacex'
,index:'pacex'
,width:150
,sortable:false
,editable:false
}],
rowNum:10,
width: 1050,
height: 300,
rowList:[10,20,30],
pager: '#pager',
sortname: 'rank',
viewrecords: true,
rownumbers: true,
gridview: true,
caption:"List",
viewPagerButtons: true
}).navGrid('#pager',{edit:true,add:false,del:false});
});
</script>
Model:
function getcontentfromtable($start, $limit, $sidx, $sord, $where, $eid){
$this->db->select('*');
$this->db->limit($limit);
$this->db->where('event_id', $eid);
if($where != NULL)
$this->db->where($where,NULL,FALSE);
$this->db->order_by($sidx,$sord);
$query = $this->db->get('table1',$limit,$start);
return $query->result();
}
What is the error message...browse your page with Google chrome and press F12 or Inspect element in right hand side you can find error..please post the error also.Check your js and css file are referred path right or not...
example:-
< script src="../../../Script/jquery-ui-1.7.2.custom.min.js" type="text/javascript" >
or use Resolve URL
Related
i am working in codeigniter and i need to show a list of destinations as row in datatables, like UK as Parent and London as Child destination.
i need to show them in datatable, i have created array of both parent and child data, but i am not able to understand, how to show them in datatable properly as each child destination row below their parent row.
something like wordpress parent and child category.
here is what i did as of now.
here is my controller
public function fetch_destinations(){
// POST data
$postData = $this->input->post();
// Get data
$data = $this->tourismo->fetch_dest_nested($postData);
echo json_encode($data);
}
this is my model
function fetch_dest_nested($postData=null)
{
$response = array();
## Read value
$draw = $postData['draw'];
$start = $postData['start'];
$rowperpage = $postData['length']; // Rows display per page
$columnIndex = $postData['order'][0]['column']; // Column index
$columnName = $postData['columns'][$columnIndex]['data']; // Column name
$columnSortOrder = $postData['order'][0]['dir']; // asc or desc
$searchValue = $postData['search']['value']; // Search value
## Search
$search_arr = array();
$searchQuery = "";
if($searchValue != ''){
$search_arr[] = " (name like '%".$searchValue."%' ) ";
}
if(count($search_arr) > 0){
$searchQuery = implode(" and ",$search_arr);
}
## Total number of records without filtering
$this->db->set_dbprefix('');
$this->db->select('count(*) as allcount');
$records = $this->db->get('destinations')->result();
$totalRecords = $records[0]->allcount;
## Total number of record with filtering
$this->db->select('count(*) as allcount');
if($searchQuery != '')
$this->db->where($searchQuery);
$records = $this->db->get('destinations')->result();
$totalRecordwithFilter = $records[0]->allcount;
//fetch records
$this->db->select("*");
if($searchQuery != '')
$this->db->where($searchQuery);
$this->db->where('level', 1);
$this->db->order_by($columnName, $columnSortOrder);
$this->db->limit($rowperpage, $start);
$this->db->from("destinations");
$q = $this->db->get();
$final = array();
if ($q->num_rows() > 0) {
foreach ($q->result() as $row) {
$this->db->select("*");
$this->db->from("destinations");
$this->db->where("parentid", $row->id);
$q = $this->db->get();
if ($q->num_rows() > 0) {
$row->children = $q->result();
}
array_push($final, $row);
}
}
$data = array();
foreach($final as $parentdest){
$data[] = array(
"id"=>$parentdest->id,
"name"=>$parentdest->name,
"slug"=>$parentdest->slug
);
}
## Response
$response = array(
"draw" => intval($draw),
"iTotalRecords" => $totalRecords,
"iTotalDisplayRecords" => $totalRecordwithFilter,
"aaData" => $data
);
return $response;
}
this is my view
<table class="apitable table dt-table" id="destlist_table">
<thead>
<th>
Destination Id</th>
<th>Destination Name</th>
<th>Destination Slug</th>
</thead>
</table>
here is my jquery code for ajax request
<script src="//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<!-- Script -->
<script type="text/javascript">
$(document).ready(function(){
var destlistDataTable = $('#destlist_table').DataTable({
'bDestroy': true,
'processing': true,
'serverSide': true,
'serverMethod': 'post',
"searching": true,
"pageLength": 10,
"order":[[0,'desc']],
'ajax': {
'url':'<?php echo admin_url('tourismo/tourismo/fetch_destinations'); ?>',
'data': function(data){
}
},
'columns': [
{ data: 'id' },
{ data: 'name' },
{ data: 'slug' },
]
});
});
what i want is every child destination row should be just below its Parent destination row, i am just not able to understand how to work with this loop here.
this is the reference for what i want
I have a SQL view in phpmyadmin which has a is used to populate data in a table created using jquery jtable. The issue is quite bizarre as only one column's data which is being pulled by the view isn't being displayed and all of the others are being displayed without an issue. There is also no issue when I edit the fields and I can see the changes I made in phpmyadmin. How do I get the Successful column to display ? All help is greatly appreciated.
Screenshot of the table
js which handles creation of the table
function getLessonsLearnedResponseChildTable(ContainerID) {
var table = {
title: '',
width: '5%',
sorting: false,
edit: false,
create: false,
display: function(data) {
//create an image to be used to open child table
var $img = $('<img src="' + config.base_url + 'assets/images/expand_row-small.png" title="View Responses" style="height:30px;width:30px;cursor:pointer;" height="30" width="30"/>');
$img.click(function() {
$('#' + ContainerID).jtable('openChildTable',
$img.closest('tr'),
{
title: data.record.event,// + ' - Response Plans'
actions: {
listAction: config.base_url + "data_fetch/responses/" + data.record.risk_id,
deleteAction: config.base_url + 'data_fetch/delete_response/',
updateAction: config.base_url + 'data_fetch/edit_response/'
},
messages: defaultResponseMessages,
fields: LessonsLearnedResponseFields
}, function(data) {//opened handler
data.childTable.jtable('load');
});
});
//return image to show on row
return $img;
}
};
return table;
}
Controller method for the listAction:
function responses($risk_id = null, $offset = 0, $limit = 100, $order_by = 'response_id', $direction = 'ASC') {
$confirm_member = $this->User_model->confirm_member(true, false);
if (!$confirm_member['success']) {
$this->print_jtable_error(self::ERROR_NOT_LOGGED_IN);
return;
}
$user_id = $_SESSION['user_id'];
$this->load->model('Response_model');
$responses = $this->Response_model->get_all($risk_id, $user_id, $limit, $offset, $order_by, $direction);
if ($responses == false) {
$this->print_jtable_error(self::ERROR_NO_ACCESS_PERMISSION);
return;
} else {
return $this->print_jtable_result($responses);
}
}
get_all method in Response Model
/*
* Retrieves all responses associated with the risk
*/
public function get_all($risk_id, $user_id, $limit = null, $offset = 0, $order_by = null, $direction = 'ASC') {
//load risk model to check if user can read from project
$this->load->model('Risk_model');
if ($this->Risk_model->initialize($risk_id, $user_id) == false) {
return false;
}
if ($limit !== null && $limit != 0) {
$this->db->limit($limit, $offset);
}
if ($order_by !== null) {
$this->db->order_by($order_by, $direction);
}
$query = $this->db->select('SQL_CALC_FOUND_ROWS *', false)->from('view_responses')->where('risk_id', $risk_id)->get();
$data = $query->result_array();
$this->load->model('Task_model');
foreach ($data as &$response)
$response['WBS'] = $this->Task_model->normalize_WBS($response['WBS']);
$data['num_rows'] = $this->db->
query('SELECT FOUND_ROWS()', false)->row(0)->{'FOUND_ROWS()'};
return $data;
}
Screenshot of the sql view
successful is received but not displayed
http://imgur.com/MqCVAGm
I've been able to solve the problem. It was an issue with spelling. I had a missing c in successful coming from the SQL view and now its working fine.
In pagination I am getting error when try to go to any pages than first page (offset=0) here is my code
URI: http://localhost/the-site/admin/hr/career_new/
URI with offset: http://localhost/the-site/admin/hr/career_new/employee_id/desc/3
Error1
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 0
Filename: .../career_model.php
Line Number: 127
Error2
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: .../career_model.php
Line Number: 127
The error line I have commented This is the error line #127 in below model code. It is right before return $ret
Model
public function sort($limit, $offset, $sort_by, $sort_order)
{
$type = $this->input->post('type');
$emp_id = $this->input->post('employee_id');
$old_operation = $this->input->post('old_operation');
$old_position = $this->input->post('old_position');
$new_operation = $this->input->post('new_operation');
$new_position = $this->input->post('new_position');
$created = $this->input->post('record_date');
$effect = $this->input->post('effective_date');
$sort_order = ($sort_order == 'desc') ? 'desc' : 'asc';
$sort_columns = array(
'type',
'employee_id',
'old_operation',
'old_position',
'new_operation',
'new_position',
'record_date',
'effective_date',
'reason',
);
$sort_by = (in_array($sort_by, $sort_columns)) ? $sort_by : 'id';
// results query
$q = $this->db
->select('*')
->from('career_path')
->like('type', $type)
->like('employee_id', $emp_id)
->like('old_operation', $old_operation)
->like('old_position', $old_position)
->like('new_operation', $new_operation)
->like('new_position', $new_position)
->like('record_date', $created)
->like('effective_date', $effect)
->limit($limit, $offset)
->order_by($sort_by, $sort_order);
$ret['rows'] = $q->get()->result();
// count query
$q = $this->db
->select('COUNT(*) as count', FALSE)
->from('career_path')
->like('type', $type)
->like('employee_id', $emp_id)
->like('old_operation', $old_operation)
->like('old_position', $old_position)
->like('new_operation', $new_operation)
->like('new_position', $new_position)
->like('record_date', $created)
->like('effective_date', $effect)
->limit($limit, $offset)
->order_by($sort_by, $sort_order);
$temp = $q->get()->result();
$ret['num_rows'] = $temp[0]->count; // This is the error line #127
return $ret;
}
Controller
public function career_new($sort_by = 'employee_id', $sort_order = 'desc', $offset = 0)
{
$this->data['title'] = '<i class="fa fa-briefcase"></i> ' . lang('crr_add');
/* * ***********************************************************
* load loop with pagination
* ****************************************************************** */
$limit = get_option('per_page');
// fields
$this->data['columns'] = array(
'id' => 'ID',
'type' => 'Type',
'employee_id' => 'Employee ID',
'old_operation' => 'Old Operation',
'old_position' => 'Old Position',
'new_operation' => 'New Operation',
'new_position' => 'New Position',
'record_date' => 'Created',
'effective_date' => 'Effected',
);
$results = $this->career_model->sort($limit, $offset, $sort_by, $sort_order);
$this->data['careers'] = $results['rows'];
$this->data['num_results'] = $results['num_rows'];
$base_url = base_url() . 'admin/hr/career_new/' . $sort_by . '/' . $sort_order;
//$numbs = $this->employees_model->filter_count();
$total_rows = $this->data['num_results'];
get_pagination($base_url, $total_rows, $limit, 6, 2, TRUE);
//$this->pagination->initialize($config);
$this->data['pagination'] = $this->pagination->create_links();
$this->data['sort_by'] = $sort_by;
$this->data['sort_order'] = $sort_order;
/* * ***********************************************************
* End: load loop with pagination
* ****************************************************************** */
$this->data['career'] = $this->career_model->get_new();
$rules = $this->career_model->rules;
$this->form_validation->set_rules($rules);
if ($this->form_validation->run() == TRUE) {
//db fields/columns to insert value
$crr_fields = array(
'type',
'employee_id',
'old_operation',
'old_position',
'new_operation',
'new_position',
'record_date',
'effective_date',
'reason',
);
$data = $this->career_model->array_from_post($crr_fields);
if (empty($data['reason'])) {
$data['reason'] = NULL;
}
$this->career_model->save($data);
$data['old_position'] = get_employee_id_field($data['employee_id'], 'position');
$data['old_operation'] = get_employee_id_field($data['employee_id'], 'operation');
/* ----------------------------------------------------------------
* Sending email once form validation runs true
--------------------------------------------------------------- */
$email_hr = $this->config->item('hr_email_templates');
$email_template = $this->config->item('crr_new_email');
$message = $this->load->view($email_hr . $email_template, $data, true);
$this->email->clear();
$this->email->from('atlassystem#apolloblake.com', get_config_option('site_name'));
$this->email->to(get_user_data('email', 1));
$this->email->subject(get_config_option('site_name') . ' - ' . $this->lang->line('crr_new_subject'));
$this->email->message($message);
if ($this->email->send()) {
// set session notification message
$this->session->set_flashdata('message', sprintf(lang('crr_record_added'), '#' . $data['employee_id']));
$this->data['message'] = $this->session->flashdata('message');
$this->session->set_flashdata('message_type', 'success');
$this->data['message_type'] = $this->session->flashdata('message_type');
redirect(current_url(), 'refresh');
} else {
$this->load->view('hr/career/form', $this->data);
}
}
$this->load->view('hr/career/form', $this->data);
}
View
<div class="panel-body">
<?php
if (validation_errors()):
echo show_alert(validation_errors(), TRUE, 'danger', 'glyphicon glyphicon-warning-sign');
endif;
?>
<div class="table-responsive">
<table cellpadding = "0" cellspacing = "0" border = "0" class = "table table-hover table-bordered datatables center" id = "">
<thead>
<tr class = "active center">
<?php foreach ($columns as $field_name => $field_display): ?>
<th <?= ($sort_by == $field_name ) ? "class=\"sort_$sort_order\"" : NULL ?>>
<?= anchor("admin/hr/career_new/$field_name/" . (($sort_order == 'asc' && $sort_by == $field_name) ? 'desc' : 'asc'), $field_display); ?>
<?= (($sort_order == 'asc' && $sort_by == $field_name) ? '<span class="glyphicon glyphicon-sort-by-attributes"></span>' : '<span class="glyphicon glyphicon-sort-by-attributes-alt"></span>'); ?>
</th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php
foreach ($careers as $crr):
echo '<tr>';
foreach ($columns as $field_name => $field_display):
echo '<td>', $crr->$field_name, '</td>';
endforeach;
echo '</tr>';
endforeach;
?>
</tbody>
</table><!--end table-->
</div>
<?php if (strlen($pagination)): ?>
<div>
<?= $pagination; ?>
</div>
<?php endif; ?>
</div>
var_dump output
using var_dump($temp); in model I am getting below on $offset=0 means first page
array (size=1)
0 =>
object(stdClass)[37]
public 'count' => string '7' (length=1)
and var_dump($ret['num_rows']);
tring '7' (length=1)
On second page with offset=3 getting error with below var_dump output
var_dump($temp);
array (size=0)
empty
and
var_dump($ret['num_rows']);
null
Okay so I have fixed the issue. It was a small and simple yet took my 4-5 hours to find and fix it.
I just did copy and paste for result and count query in model and there I made a mistake. I just overlooked the last two ->limit(), and ->order_by() function which was not required for count total rows. This was creating issue. When use pagination it was counting limit and offset. So final fixed code is as below
Model
public function sort($limit, $offset, $sort_by, $sort_order)
{
$type = $this->input->post('type');
$emp_id = $this->input->post('employee_id');
$old_operation = $this->input->post('old_operation');
$old_position = $this->input->post('old_position');
$new_operation = $this->input->post('new_operation');
$new_position = $this->input->post('new_position');
$created = $this->input->post('record_date');
$effect = $this->input->post('effective_date');
$sort_order = ($sort_order == 'desc') ? 'desc' : 'asc';
$sort_columns = array(
'type',
'employee_id',
'old_operation',
'old_position',
'new_operation',
'new_position',
'record_date',
'effective_date',
'reason',
);
$sort_by = (in_array($sort_by, $sort_columns)) ? $sort_by : 'id';
// results query
$q = $this->db
->select('*')
->from('career_path')
->like('type', $type)
->like('employee_id', $emp_id)
->like('old_operation', $old_operation)
->like('old_position', $old_position)
->like('new_operation', $new_operation)
->like('new_position', $new_position)
->like('record_date', $created)
->like('effective_date', $effect)
->limit($limit, $offset)
->order_by($sort_by, $sort_order);
$ret['rows'] = $q->get()->result();
// count query
$q = $this->db
->select('COUNT(*) as count', FALSE)
->from('career_path')
->like('type', $type)
->like('employee_id', $emp_id)
->like('old_operation', $old_operation)
->like('old_position', $old_position)
->like('new_operation', $new_operation)
->like('new_position', $new_position)
->like('record_date', $created)
->like('effective_date', $effect); // removed limit and order_by
$temp = $q->get()->result();
$ret['num_rows'] = $temp[0]->count; // This is the error line #127
return $ret;
}
I realize there are some related questions but I couldn't find what I was looking for. I used jqgrid many times in the past but forgot how to achieve server side pagination.
here is my javascript
$("#list").jqGrid({
url: "index.php?loadData=test",
datatype: "json",
mtype: "GET",
colNames: ["id", "eNodeB_unique", "enodeB_type", "radio_freq_mod", "macroEnbId_dec representation", "num_cells"],
colModel: [
{ name: "id", width: 55 },
{ name: "enodeB_unique", width: 90 },
{ name: "enodeB_type", width: 80, align: "right" },
{ name: "radio_freq_mod", width: 80, align: "right" },
{ name: "macroEnbId_dec_rep", width: 80, align: "right" },
{ name: "num_cells", width: 150, sortable: false }
],
pager: "#pager",
rowNum: 10,
rowList: [10, 20, 30],
sortname: "id",
sortorder: "desc",
viewrecords: true,
gridview: true,
autoencode: true,
caption: "My first grid",
loadonce:false
});
and my server side code
public function getData($page, $limit, $sidx, $sord){
$query_str = "SELECT COUNT(*) AS count FROM tbl";
$prepState = $this->DBi->prepare($query_str);
$result = $this->DBi->query($prepState);
$count = $result[0]['count'];
if( $count > 0 && $limit > 0) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages){
$page = $total_pages;
}
$start = $limit * $page - $limit;
if($start < 0){
$start = 0;
}
$query_str = "SELECT * FROM tbl ORDER BY {$sidx} {$sord} LIMIT {$start}, {$limit}";
$prepState = $this->DBi->prepare($query_str);
$result = $this->DBi->query($prepState);
return $result;
}
if I keep $start and $limit in the query then i just get the inital ten results. If I take those out... then my grid shows all my results.. but there is only one page available. I have on option to click on the next page.
EDIT:
okay I realize now that I have to return this information.. I'm puzzled by the way I have to return the rows. Was JQgrid always this way?
$query_str = "SELECT * FROM enodeB ORDER BY {$sidx} {$sord} LIMIT {$start}, {$limit}";
$prepState = $this->DBi->prepare($query_str);
$result = $this->DBi->query($prepState);
$finalRows = array();
foreach($result as $row){
$finalRows[] = array('cell'=> $row);
}
return array('page' => $page, 'total' => $total_pages, 'records' => $count, 'rows' => $finalRows);
public static dynamic ToJson<T>(this IEnumerable<T> Collection, string sidx, string sord, string page, string rows, List<string> Columns)
{
return ToJson<T>(sidx, sord, page, rows, Collection, Columns);
}
private static dynamic ToJson<T>(string sidx, string sord, string page, string rows, IEnumerable<T> Collection, List<string> Columns)
{
page = page.NotNull("1"); rows = rows.NotNull("100"); sidx = sidx.NotNull("Id"); sord = sord.NotNull("asc");
int pageIndex = Convert.ToInt32(page) - 1;
int pageSize = Convert.ToInt32(rows);
int totalRecords = Collection.Count();
int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
if (!Collection.IsNull())
{
Collection = Collection.ToList().OrderWith(x => x.GetPropertyValue(sidx), sord).Skip(pageSize * pageIndex).Take(pageSize);
return JsonData<T>(Collection, totalPages, page, totalRecords, Columns);
}
return BlankJson();
}
private static dynamic JsonData<T>(IEnumerable<T> collection, int totalPages, string page, int totalRecords, List<string> Columns)
{
var colsExpr = Columns.ConvertAll<PropertyInfo>(x => Extentions.GetProperty<T>(x));
var jsonData = new
{
total = totalPages,
page = page,
records = totalRecords,
rows = collection.Select(row => new { id = row.GetPropertyValue("Id") ?? Guid.NewGuid(), cell = GetValues<T>(colsExpr, row) }),
};
return jsonData;
}
public static dynamic BlankJson()
{
return new
{
total = 0,
page = 0,
records = 0,
rows = "",
};
}
private static string[] GetValues<T>(List<PropertyInfo> columns, T obj)
{
var values = new List<string>();
try
{
foreach (var x in columns)
{
var temp = x.GetValue(obj, null);
values.Add(temp != null ? temp.ToString() : string.Empty);
}
return values.ToArray();
}
catch
{
return values.ToArray();
}
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am using the browser-layout example for my application
I'm trying to add a two trees to it.
I'm trying to define the twotrees in a separate file, my main file is the layout-browser.js and i need to add this (and others) in the tabs I have in it.
The problem is that I'm using .net and the example is using php
How can I make this work in .net?
Here is my code:
Ext.require(['*']);
var store = Ext.create('Ext.data.TreeStore', {
proxy: {
type: 'ajax',
url: 'get-nodes.php'
},
root: {
text: 'Ext JS',
id: 'src',
expanded: true
},
folderSort: true,
sorters: [{
property: 'text',
direction: 'ASC'
}]
});
var tree = Ext.create('Ext.tree.Panel', {
id: 'tree',
store: store,
width: 250,
height: 300,
columnWidth: 0.5,
viewConfig: {
plugins: {
ptype: 'treeviewdragdrop',
appendOnly: true
}
}
// ,renderTo: document.body
});
var store2 = Ext.create('Ext.data.TreeStore', {
proxy: {
type: 'ajax',
url: 'get-nodes.php'
},
root: {
text: 'Custom Ext JS',
id: 'src',
expanded: true,
children: []
},
folderSort: true,
sorters: [{
property: 'text',
direction: 'ASC'
}]
});
var tree2 = Ext.create('Ext.tree.Panel', {
id: 'tree2',
width: 250,
height: 300,
columnWidth: 0.5,
store: store2,
viewConfig: {
plugins: {
ptype: 'treeviewdragdrop',
appendOnly: true
}
}
// ,renderTo: document.body
});
Ext.define("Ext.app.myTwoTrees",{
extend:"Ext.panel.Panel",
width : 600,
height: 350,
layout: 'column',
items: [
tree , tree2
]
});
I call it in my tab like this:
Ext.create('Ext.app.myTwotrees')
here is the get-nodes.php
<?php
// from php manual page
function formatBytes($val, $digits = 3, $mode = 'SI', $bB = 'B'){ //$mode == 'SI'|'IEC', $bB == 'b'|'B'
$si = array('', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y');
$iec = array('', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi');
switch(strtoupper($mode)) {
case 'SI' : $factor = 1000; $symbols = $si; break;
case 'IEC' : $factor = 1024; $symbols = $iec; break;
default : $factor = 1000; $symbols = $si; break;
}
switch($bB) {
case 'b' : $val *= 8; break;
default : $bB = 'B'; break;
}
for($i=0;$i<count($symbols)-1 && $val>=$factor;$i++)
$val /= $factor;
$p = strpos($val, '.');
if($p !== false && $p > $digits) $val = round($val);
elseif($p !== false) $val = round($val, $digits-$p);
return round($val, $digits) . ' ' . $symbols[$i] . $bB;
}
// grab the custom params
$path = isset($_REQUEST['path'])&&$_REQUEST['path'] == 'extjs' ? '../../../' : '../../';
$node = isset($_REQUEST['node']) ? $_REQUEST['node'] : '';
$isXml = isset($_REQUEST['isXml']);
if(strpos($node, '..') !== false){
die('Nice try buddy.');
}
$nodes = array();
$directory = $path.$node;
if (is_dir($directory)){
$d = dir($directory);
while($f = $d->read()){
if($f == '.' || $f == '..' || substr($f, 0, 1) == '.') continue;
$filename = $directory . '/' . $f;
date_default_timezone_set('America/Los_Angeles');
$lastmod = date('M j, Y, g:i a', filemtime($filename));
if(is_dir($directory.'/'.$f)){
$qtip = 'Type: Folder<br />Last Modified: '.$lastmod;
$nodes[] = array(
'text' => $f,
'id' => $node.'/'.$f,
'cls' => 'folder'
);
} else {
$size = formatBytes(filesize($filename), 2);
$qtip = 'Type: JavaScript File<br />Last Modified: '.$lastmod.'<br />Size: '.$size;
$nodes[] = array(
'text' => $f,
'id' => $node.'/'.$f,
'leaf' => true,
'cls' => 'file'
);
}
}
$d->close();
}
if ($isXml) {
$xmlDoc = new DOMDocument();
$root = $xmlDoc->appendChild($xmlDoc->createElement("nodes"));
foreach ($nodes as $node) {
$xmlNode = $root->appendChild($xmlDoc->createElement("node"));
$xmlNode->appendChild($xmlDoc->createElement("text", $node['text']));
$xmlNode->appendChild($xmlDoc->createElement("id", $node['id']));
$xmlNode->appendChild($xmlDoc->createElement("cls", $node['cls']));
$xmlNode->appendChild($xmlDoc->createElement("leaf", isset($node['leaf'])));
}
header("Content-Type: text/xml");
$xmlDoc->formatOutput = true;
echo $xmlDoc->saveXml();
} else {
echo json_encode($nodes);
}
I would recommend you break the problem into two pieces:
1) change url: 'get-nodes.php' to url: 'my-dotnet-url and make the .NET page return static JSON or XML (hardcode the values to the tree)
That will confirm all your javascript, resources, etc. is working properly and that you are only asking a .NET question about how to output certain data.
2) Then find a .NET example that will let you create JSON or XML from wherever you are getting data (I'm guessing probably a database). You just need the output to look like your static data that worked correctly. If you don't know much PHP or .NET learning .NET to get your output correct would be easier than trying to port over that example. If you get stuck, I'd repost a different question and ask how to output the data that results from that static file dynamically and don't have the extjs complication involved!
Hope this helps.
Try Dextop. It's an application framework for connection between ASP.NET and Ext JS.