Mục lục:
1. Chức năng
2. Cấu hình xmlObject
Một số cấu hình url
3. Một số ứng dụng làm ứng dụng web
3.1. Sắp xếp lại cột trên lưới
3.2. Tính tổng
3.3. Định dạng điều kiện cho 1 cột
3.4. Thêm nút lọc tìm kiếm
3.5. Thêm nút xuất Excel, PDF, print vào DataTable
3.6. Thay đổi lại tiêu đề trang từ JS
3.7. Gọi các query thực thi lệnh từ button
1. Chức năng
Trang lấy dữ liệu từ query và hiển thị ra dạng lưới, có thể thay đổi lại giao diện từ xml_Object
Dường dẫn truy cập:
xml_getdata_q.aspx?file=NhaHang/BaoCao_NVL_by_HopDongKey&index=1
* Tại query có nút liên kết chuyển đến đường dẫn phía trên
2. Cấu hình xmlObject
** Với ví dụ thư mục NhaHang có Query tên BaoCao_NVL_by_HopDongKey
Khi truy cập:
xml_getdata_q.aspx?file=NhaHang/BaoCao_NVL_by_HopDongKey&index=1
** Thì tạo xml_Object là:
Thư mục xml_Object/__Query/NhaHang/BaoCao_NVL_by_HopDongKey.xml
*** CHÚ Ý: __ trước Query
Tạo file có cú pháp
Tạo bảng ghi có name là 0 nếu lấy table 0
Tạo bảng ghi có name là 1 nếu lấy table 1
(Vì query trả về nhiều table cùng 1 lúc, nếu 1 table thì chỉ tạo là 0)
Ví dụ:
BaoCao_NVL_by_HopDongKey
* Chú ý: Query trả nhiều table có index=0 ... n thì khi tạo xmlObject
-> bảng ghi 1 có name=0
-> bảng ghi 2 có name=1
Cấu hình được lấy từ tab Grid View trong giao diện xmlObject
** Một số URL của query view khi sử dụng
* Thêm thêm trên url:
bt_Close_Frm_Popup=1 thì có xuất hiện thêm nút đóng và đóng nạp lại (khi có sử dụng cửa sổ popup)
3. Một số ứng dụng hay sử dụng khi làm web app
=============================================
3.1. Sắp xếp lại cột trên lưới
Cấu hình thêm lệnh trong Grid_Config
<#js_cf_datatable:
order: [[1, 'desc']]
:js_cf_datatable#>
số 1 là cột thứ 1, thay thế lại cho phù hợp
3.2. Tính tổng
Cấu hình thêm lệnh trong Grid_Config
Nguyên lý:
$('#dataTable').DataTable(
{
"paging": false,
"info": false,
Lệnh_Thêm
}
**********
** Khi thêm nếu nhiều lệnh phải thêm dấu , (nếu không sẽ lỗi)
Cách 1: không có tổng theo tìm kiếm
<#js_cf_datatable:
footerCallback: function (row, data, start, end, display) {
var api = this.api();
// Remove the formatting to get integer data for summation
var intVal = function (i) {
// alert(i); $. là từ thay thế tiền
return typeof i === 'string' ? i.replace(/[\$.]/g, '') * 1 : typeof i === 'number' ? i : 0;
};
var VITRI_COT=Vị Trí Cột(tính tự 0 trái sang phải;
// Total over all pages
total = api
.column(VITRI_COT)
.data()
.reduce(function (a, b) {
return intVal(a) + intVal(b);
}, 0);
// Update footer
$(api.column(VITRI_COT).footer()).html( "<div class='text-right'>"+ total.NumFormat() +"</div>");
},
:js_cf_datatable#>
Cách 2: Có tổng theo tìm kiếm
<#js_cf_datatable:
footerCallback: function (row, data, start, end, display) {
var api = this.api();
// Remove the formatting to get integer data for summation
var intVal = function (i) {
// alert(i); $. là từ thay thế tiền
return typeof i === 'string' ? i.replace(/[\$,]/g, '') * 1 : typeof i === 'number' ? i : 0;
};
var VITRI_COT=Vị Trí Cột(tính tự 0 trái sang phải;
// Total over all pages
total = api
.column(VITRI_COT)
.data()
.reduce(function (a, b) {
return intVal(a) + intVal(b);
}, 0);
// Total over this page
pageTotal = api
.column(VITRI_COT, { page: 'current' })
.data()
.reduce(function (a, b) {
return intVal(a) + intVal(b);
}, 0);
// Update footer
$(api.column(VITRI_COT).footer()).html('$' + pageTotal + ' ( $' + total + ' total)');
},
:js_cf_datatable#>
3.3. Định dạng điều kiện cho 1 cột
dđ
3.4. Thêm nút lọc tìm kiếm
Tại: Grid_Config thêm lệnh
<SqlParameterHelp>
<0>
Loai<pr&/>Loại
Loai2<pr&/>Loại 2
</0>
</SqlParameterHelp>
<0> là query thứ 1
****** tương lai: tạo nút có chọn popup lưới
3.5. Thêm nút xuất Excel, PDF, print vào DataTable
Thêm code sau vào:
Grid_Config:
<#js_cf_datatable:
dom: 'Bfrtip',
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print'
]
:js_cf_datatable#>
Cách: không có css nút lệnh
<#html_add_end_masterpage:
<script src="/vendor/datatables/lib/dataTables.buttons.min.js" type="text/javascript"></script>
<script src="/vendor/datatables/lib/jszip.min.js" type="text/javascript"></script>
<script src="/vendor/datatables/lib/pdfmake.min.js" type="text/javascript"></script>
<script src="/vendor/datatables/lib/vfs_fonts.js" type="text/javascript"></script>
<script src="/vendor/datatables/lib/buttons.html5.min.js" type="text/javascript"></script>
<script src="/vendor/datatables/lib/buttons.print.min.js" type="text/javascript"></script>
:html_add_end_masterpage#>
*** Thêm <link href="/vendor/datatables/lib/buttons.dataTables.min.css" rel="stylesheet">
Để có style button
* html_add_end_masterpage sẽ thêm cuối trang master
*** Khi print cần thay đổi lại tiêu đề cần thêm code:
3.6. Thay đổi lại tiêu đề trang từ JS
Vào cấu hình lại từ Grid_Page_AddHtml
<script>
document.title = "Loading ... ";
$.get("/Adminxml/Query_Do.aspx?name=NhaHang/HopDong_Load_Key&out=json&key=<iif-D>Url:key</iif-D>", function(data, status){
document.title = "Nguyên vật liệu - hợp đồng: "+data.Q1[0].So +", ngày: " + covertDateToStr(data.Q1[0].NgayThueMatBang)
$(".title_grv").append("<br>"+document.title);
});
</script>
3.7. Gọi các query thực thi lệnh từ button
- Thêm liên kết từ trang cần gọi:
Vào cấu hình: Grid view -> Grid_Describe_Hearder
<a class="bt_open_w_pIIF btn btn-outline-danger" p_l="/Adminxml/xml_getdata_q.aspx?file=Ten_PROCEDURE&config_sys=nomaster&config_class_hide=bt_sys_config,title_grv,dataTables_filter,btgr_sys_bottom" p_w="700px" p_h="300px" p_t="Title" data-toggle="modal" data-target="#Obj_popup_pIIF" href="#"><i class="far fa-copy"></i> Mô tả liên kết</a>
- Nếu muốn có hỏi YES/NO
<a class="bt_open_w_pIIF_alert btn btn-outline-danger" p_alert="Bạn có xóa nhật ký đồng bộ?" p_l="/adminxml/xml_getdata_q.aspx?file=BanHang_iif/tbDongBo_Client_DEL&config_sys=nomaster&config_class_hide=bt_sys_config,title_grv,dataTables_filter,btgr_sys_bottom" p_w="700px" p_h="300px" p_t="Kết quả" data-toggle="modal" data-target="#Obj_popup_pIIF" href="#"><i class="far fa-copy"></i> Xóa nhật ký</a>
Thêmtrên url: bt_Close_Frm_Popup=1 trong phần p_l để có nút nạp lại
- Phần tạo query có thể tạo lệnh trực tiếp, hay tạo bằng PROCEDURE
- Nếu tạo query: có tên PROCEDURE_CopyTenNVL_To_DMNVL
<Query>
<ID>monan</ID>
<Src>cnSQL_HDND</Src>
<Type>Sql</Type>
<Cmd>
Ten_PROCEDURE
-- Chú ý: phải có giá trị trả về 1 row để chỉ kết quả số bảng ghi thực thi
</Cmd>
</Query>
- Tạo PROCEDURE từ SQL Server: xem cách tạo
CREATE PROCEDURE [dbo].[Ten_PROCEDURE]
@_ts nvarchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
IF IsNull(@_ts,'')=''
BEGIN
Select N'Rỗng @_ts'
RETURN;
END
--print @NoiDung_KEY_ThanhLy
Declare @Cot1 nvarchar(50)
Declare @Cot2 nvarchar(50)
DECLARE Ten_cursor CURSOR FOR
SELECT Cot1,Cot2 From TB
Where CotTim=@_ts
OPEN Ten_cursor
FETCH NEXT FROM HDCT_cursor
INTO @Cot1,@Cot2
WHILE @@FETCH_STATUS = 0
BEGIN
--print ' ' + CAST(@Cot1 as varchar(50))
IF NOT EXISTS (
SELECT *
FROM TB_TIM
--Where ...
)
BEGIN
-----------------
print 'test'
--DECLARE @KEY_New UNIQUEIDENTIFIER
--SET @KEY_New = NEWID()
--Insert Into TB_CHEN(..)
--Values( LOWER(@KEY_New) )
-----------------
END
ELSE
BEGIN
print 'test'
END
FETCH NEXT FROM Ten_cursor
INTO @Cot1,@Cot2
END --WHILE @@FETCH_STATUS = 0
CLOSE Ten_cursor ;
DEALLOCATE Ten_cursor ;
Select Cast( @SoRow as nvarchar(50)) as XL_Thành_Công
-------
---- END
END
Hiển thị dữ liệu query theo định dạng tùy chọn, cấu hình từ xmlObject